Banane wrote:
I'm asking that because I have a framework that works with a parent entity and every time I have to create the parent I don't know what will be the possible children that will be created.
Is there a way to know if an entity has been created ? Checking Null or something like that?
ie I have Client, Contact, Adress tables...it is 1:1-1:1 relation
A) I create the client....but not the contact and the address because I don't know yet if I will have data for it...so I don't want to create empty record or SQL !
So If the user decides to enter information for the contact/address; I want to check if the contact and address have been created and assigned to the client?
ie
ClientEntity client = new ClientEntity();
client.Name = "client1";
.
.
In an other page....
// ** IT IS NOT NULL HERE ** it doesn't go there!!!!!!
if( client.Contact == null)
client.Contact = new ContactEntity();
client.Contact.Name = "Jim";
You should do:
if(client.Contact.IsNew)
{
// create new
}
Lazy loading code returns a new entity if the entity required is not found.
*** I Found ***
client.ContactReturnsNewIfNotFound = false;
if( client.Contact == null)
client.Contact = new ContactEntity(); // goes here now...
*** ReturnsNewIfNotFound is set to true by default !!!! is there a way to set it to false by default ???? I have to change the template I guess??
It is set to true by default because the initial behavior of the code is as it is today: returning a new entity if the entity is not found. Changing this will break existing code, so I can only do that if I know there isn't existing code using the library, which is not an option at the moment. I made the flag so people can set it to false if they want to.
With 1.0.2004.2, which is almost done so will go in beta next week (I thought I'd finish it before the weekend however it took longer than expected), you can add a template binding to a template file to your templateset in which you add the flag settings and which are then generated into each and every entity by default and that code will be ran during entity initialization. At the moment you're out of luck, you have to set it manually or test for IsNew.