|
Brady Kelly wrote: Something long winded What else is new with SQL?
|
|
|
|
|
Do you have an insert trigger behind this table in the database by any chance? It would seem to be consistent.
|
|
|
|
|
No. The table is created by EF Code First, nothing but the table itself. Not even indexes but for the PK. I think it's something to do with EF trying to also save another child of the same parent, and clashing somewhere far away.
|
|
|
|
|
|
with EF, it helps you out and takes care of all the FK IDs for you You can fill the nested object and let it handle all the FKs (don't even set the ID properties)
ie:
parentObject.Project = newProject;
_projectRepositroy.Insert(parentObject);
|
|
|
|
|
EF should do that, but somewhere something is amiss - probably my fluent mappings - and I had to resort to the manual update you see in the code excerpt.
|
|
|
|
|
In a project i had to refactor:
if (!string.isNullOrEmpty(User.ToString())) {
}
null.ToString() ?? sweet
|
|
|
|
|
Bob Dole The internet is a great way to get on the net.
2.0.82.7292 SP6a
|
|
|
|
|
I'm not sure I get what's wrong here with the given amount of context (except that ToString probably shouldn't return null...but it certainly could if it's overloaded)
|
|
|
|
|
ToString is an instance method, and if the user variable is null, there will be an unhandled NullReferenceException when the ToString() is called, as you cannot call a method on a null object.
Bob Dole The internet is a great way to get on the net.
2.0.82.7292 SP6a
|
|
|
|
|
Right, but there's no reason to expect it might be null at this piece of code without more context. The previous line could be something that gets that user from a function that always returns an non-null object...I just don't think there's enough information to comment on the code as-is.
|
|
|
|
|
I understand your logic, but User can be null.
But either way turned ToString in this situation is also completely redundant because IsNullOrEmpty already does 2 specific checks. Is the item null, or is the item an empty string.
So the correct code, without triggering a NullReferenceException should have been
if (!string.IsNullOrEmpty(User)) {
}
|
|
|
|
|
Oh is User a string? If so I get it now...
|
|
|
|
|
Yeah it's a string and probably read UserName originally. Sorry for the confusion
|
|
|
|
|
Calling ToString() on a string is totally unexpected. Perfectly valid code, but I'd wonder about the programmer who wrote it.
How that line ever got written in the first place made a lot more sense when I was thinking User wasn't a string -- you can't pass a non-string to IsNullOrEmpty(). Still broke, but I can see someone making such a mistake if in a hurry. Any chance it wasn't a string at one time?
We can program with only 1's, but if all you've got are zeros, you've got nothing.
|
|
|
|
|
You are correct. That is the existing implementation (or null handling). In my opinion, it would be nice to allow the conversion (.ToString()) from null to an empty string. When something is nothing (null), it is logical to think it is an empty in terms of a string. However, this ertainly not applicable to other data types.
TOMZ_KV
|
|
|
|
|
True. That would be useful.
Bob Dole The internet is a great way to get on the net.
2.0.82.7292 SP6a
|
|
|
|
|
Zac Greve wrote: ToString is an instance method
Replace it with an extension-method
|
|
|
|
|
Returning null from a ToString would be worthy of a WTF of its own.
|
|
|
|
|
i prefer:
if(User != null && User.ToString() != "")
|
|
|
|
|
how about this.
if( User != null && User.Length != 0) is better than checking for empty string ???
Jibesh.V.P
India
|
|
|
|
|
Why didn't i though it?
|
|
|
|
|
Maybe they have CDO?
if (!string.IsNullOrEmpty(User.ToString().ToString().ToString().ToString())) {
}
|
|
|
|
|
CDO. It's like OCD, just in alphabetical order like it should be!
Bob Dole The internet is a great way to get on the net.
2.0.82.7292 SP6a
|
|
|
|
|