|
Hi Kevin,
I think you have to associate by providing the foreign key in the relationship.
Property(c => c.Company).IsRequired().WithMany()
.HasForeignKey(u => u.CompanyId);
|
|
|
|
|
I hope this is the correct place to post this. If not, please help me correct it.
Lately, I have been digging around in open source projects at SourceForge.net. I download the source for an interesting project, typically if it seems like something I may learn from. I may be working on a project in which I need to create a custom control and I would like a good code example that I can study. Once the source is downloaded and I extract it as needed, I load the solution in Visual Studio 2010.
Once I begin digging through some of the code my head begins to hurt. It hurts terribly. For one, I see little white space in many projects. And two, the thing that really gets me, is the fact that variables have completely meaningless names, usually just one or two letters. It looks like this (not real code; just an example):
Dictionary<string, int> d = new Dictionary<string, int>();
private void MyMethod(string p, int q)
{
bool b = p == "string1" ? true : false;
List<string> l = GetList(b);
foreach (string k in l)
{
if (!string.IsNullOrWhiteSpace(p) && q > 0)
d.Add(l, q);
}
}
Before I continue, what does the fact that p == "string1" have to do with anything? Also, what does GetList(bool) do and how does the value of 'b' affect the results?
The first thing I tend to notice is that there is no documentation (///<summary>) for the method. Adding those comments too methods and classes is typically the first thing I do when I am coding. Maybe it isn't a recommended practice but instead it is just my own "standard"/style? If so, that's fine. Should this be something everyone uses?
The comments are typically quite vague as well. Or comments are missing entirely, even in methods that contain a lot of code. And in MyMethod, how should you really know what "d" is when it is declared in another file/class? And why exactly does "q > 0" have to be met before adding the item? This isn't a perfect example but I'm not on the computer I use when browsing through these projects. Perhaps I am being overly conscious about coding practices, standards, whatever. But I find it very difficult to read the code at times.
Another thing that bugs me slightly, though I guess it's expected when anyone can contribute to the project, is the lack of a consistent coding style. That doesn't bug me near as much as the rest. It's just a thought that I figured I'd throw in here.
djj55: Nice but may have a permission problem
Pete O'Hanlon: He has my permission to run it.
|
|
|
|
|
My 2 cts:
1.
The worst style aspect is using single-letter identifiers, especially for the method itself and its parameters. Giving them meaningful names makes things a lot easier to understand. And they might show up in Intellisense or something similar, making the use of the method a lot easier.
2.
Yes, a method-level comment (a "contract") explaining what the method promises to do for you would be nice (unless #1 fixed all that already).
3.
About why "string1" and "q>0" are there I can't tell you anything, as I have no clue what the purpose of the whole thing is.
|
|
|
|
|
I don't know, but there's a lot of ugly code there.
0) Yes, the Dictionary should have a better name (and maybe it should have an access modifier).
1) ? true : false seems unnecessary.
2) if (!string.IsNullOrWhiteSpace(p) && q > 0) should probably wrap everything else.
3) I generally put XML documentation comments on code I publish, but I get lazy too.
4) I would prefer d [ l ] = q over d.Add(l, q)
5) You'll have to read GetList to see what it does
|
|
|
|
|
I agree. I'm just trying to find out why people think this is okay. Haha. I've seen practically identical examples on so many occasions and it just blows my mind. I mean, I do slip up once in a while, forgetting XML documentation, lazily naming a few variables, etc. But certainly if I were to contribute to an open source project I would want to use the best standards/practices that I was aware of. It's not like working in a team in the same room/office, where the other contributors could at least walk over to you and say "what the **** is this?" Haha.
djj55: Nice but may have a permission problem
Pete O'Hanlon: He has my permission to run it.
|
|
|
|
|
Matt U. wrote: . . . lazily naming a few variables, etc.
I really do try to use meaningful variable names. But sometimes I can't think of one that I haven't used elsewhere for a similar purpose...so I get frustrated and just use the first thing pops into my head.
So if you ever see a variable called BuffaloFart, do not attempt to divine a legitimate meaning. There may not be one.
|
|
|
|
|
GenJerDan wrote: So if you ever see a variable called BuffaloFart, do not attempt to divine a legitimate meaning. There may not be one.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|
|
I don't recall any BuffaloFart variables in any of my code. However, I have been stuck as well and I have chosen something like "blah1", "blah2" and "blah3". They were all related in terms of how they were used. Haha.
djj55: Nice but may have a permission problem
Pete O'Hanlon: He has my permission to run it.
|
|
|
|
|
Matt U. wrote: Adding those comments too methods and classes is typically the first thing I do when I am coding +5
Me too. I always comment and organize my code. I don't enjoy spending hours trying to figure out what a developer (who's no longer at the copany) intended to do in a bunch of obtuse code and would hate to have a consumer of my code endure the same pain.
/ravi
|
|
|
|
|
Haha, yeah. I know what you mean. I am the only developer in my facility, a manufacturing environment. I'm not technically a developer (my job title, that is) but that is exactly what my job is. I write in-house applications. But even without others looking at my code, I get in the mindset like I do work on a team rather than solo. Just an extra precaution, I reckon.
djj55: Nice but may have a permission problem
Pete O'Hanlon: He has my permission to run it.
|
|
|
|
|
Matt U. wrote: Perhaps I am being overly conscious about coding practices, standards, whatever.
But I find it very difficult to read the code at times.
Unfortunately that is how the real world works.
I am hopeful that the example you posted is one of the worst rather than average.
All you can do is endeavor to make sure that no one ever asks (or thinks) the same thing about your code.
So make sure your code has comments, insure that if you are modifying existing code that it matches the existing style, give your variables better names and remove unused code.
Matt U. wrote: typically if it seems like something I may learn from.
Hopefully you have learned that it is likely that other people will look at your code, and will want/need to understand it and so you should write your code that reflects that understanging.
|
|
|
|
|
That makes sense. I definitely go into a project with the assumption that someone may eventually look at my code. And with the way things are going lately, that may be the case soon.
djj55: Nice but may have a permission problem
Pete O'Hanlon: He has my permission to run it.
|
|
|
|
|
Good afternoon to all.
Here's my problem:
I've created a WCF service and now I'm trying to install it with Installer project on target machine as administrator.
host = new ServiceHost(serviceType, serviceUri);
host.Open();
And here's exception:
HTTP could not register URL http:
When I start serviceCore as console application - it works fine.
What I'd tried:
- netsh;
- manifest with highestAvailable;
- turn off UAC;
ServiceInstaller is NetworkService, target machine OS is R2, domain user has adm rights.
|
|
|
|
|
Its easy
you can use this using directive
using System.ServiceModel
|
|
|
|
|
sina rahimzadeh wrote: you can use this using directive
That has absolutely nothing to do with it.
The OP doesn't have a compile problem.
|
|
|
|
|
He can sacrifice a chicken as well. It's as relevant as your answer.
|
|
|
|
|
even turkey can't help me -/
modified 1-Jun-12 10:18am.
|
|
|
|
|
|
as I've said, I'd already used "netsh"
I'd added localhost, ip, + with my domain user or Everyone. But it still doesn't work)
|
|
|
|
|
first remove that port and then reserve it again, or change your port, maybe its allready reserved by another service!
|
|
|
|
|
How to add audio to a form.
|
|
|
|
|
|
|
DON'T SHOUT. Using all capitals is considered shouting on the internet, and rude (using all lower case is considered childish). Use proper capitalisation if you want to be taken seriously.
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|