Need some opinion on Null Check

Posts   
 
    
MarcoP avatar
MarcoP
User
Posts: 270
Joined: 29-Sep-2004
# Posted on: 29-Aug-2006 14:08:30   

Ok, I wrote a routine that basically enumerates through the fields collection and raises an exception if any of the columns that do not allow null do not have a value set. All this works fine an dandy, but I just ran into a problem. Basically, I have a column NoteID (foreign key) which is required and I do not set, but I do create a NoteEntity and associate it with the entity. So, my routine thinks that the NoteID has not been set. Can anyone think of a way for me to add this extra check generically?

Thanks

mihies avatar
mihies
User
Posts: 800
Joined: 29-Jan-2006
# Posted on: 29-Aug-2006 14:55:09   

MarcoP wrote:

Ok, I wrote a routine that basically enumerates through the fields collection and raises an exception if any of the columns that do not allow null do not have a value set. All this works fine an dandy, but I just ran into a problem. Basically, I have a column NoteID (foreign key) which is required and I do not set, but I do create a NoteEntity and associate it with the entity. So, my routine thinks that the NoteID has not been set. Can anyone think of a way for me to add this extra check generically?

Thanks

I would modify the template to get this information out (check both relation and fkidfield).

MarcoP avatar
MarcoP
User
Posts: 270
Joined: 29-Sep-2004
# Posted on: 29-Aug-2006 15:06:04   

mihies wrote:

I would modify the template to get this information out (check both relation and fkidfield).

Ok, thanks! I haven't ventured into modifying the templates before, but are you thinking that I should modify the templates to expose a property that performs this check?

mihies avatar
mihies
User
Posts: 800
Joined: 29-Jan-2006
# Posted on: 29-Aug-2006 15:52:28   

MarcoP wrote:

Ok, thanks! I haven't ventured into modifying the templates before, but are you thinking that I should modify the templates to expose a property that performs this check?

Yes, something like that. Perhaps there is a simplier way, but I don't see it.

Jessynoo avatar
Jessynoo
Support Team
Posts: 296
Joined: 19-Aug-2004
# Posted on: 29-Aug-2006 16:43:40   

I think there should be another way to do so without altering the code:

GetDependentRelatedEntities() should give you the list of related entities.

Then GetEntitySyncInformation(relatedEntity) will give you a Dictionary<string, EntitySyncInfo<IEntity2>> where string are the field names, and EntitySyncInfo has a "Used" property which should let you discriminate the related entities not saved already.

Well I might not have this completely right, but it should be something close.

Edit: Just realized the second method is protected. Looking for another solution...

Jessynoo avatar
Jessynoo
Support Team
Posts: 296
Joined: 19-Aug-2004
# Posted on: 29-Aug-2006 17:10:06   

Ok I think Frans will have the last word here, cause I'm just getting nowhere searching in the UtilityClasses.cs...

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 30-Aug-2006 10:21:20   

Jesse's answer is probably the best. You can also generate some code which tests if a related entity is set if an FK field isn't changed.

Frans Bouma | Lead developer LLBLGen Pro