Initializing new (and only new) Entities

Posts   
 
    
Bombus
User
Posts: 8
Joined: 15-Apr-2009
# Posted on: 15-Apr-2009 11:24:48   

LLBLGEN Pro 2.6 Final SelfServicing, TwoClasses

Hello everyone,

how can I initialize new Entities with default values? I tried this

 protected override void OnInitialized()
        {
            base.OnInitialized();
            if (this.IsNew)
            {
                InitNewEntity(); // set default values; this.fielda = "aaa".....
            }
        }

But this event "OnInitialized()" will be called also for existing Entities, before there will be fetched. Is there an Event which will only be called, if the Entity is realy new?

I could use this code in my Form:

MyEntity ent = new MyEntity();
if (ent.IsNew())
{
   InitNewEntity();
}

This would work. But I want to use this logic inside my entity.

Can anyone give me an hint?

Thanks,

Alex

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 15-Apr-2009 11:28:23   
Bombus
User
Posts: 8
Joined: 15-Apr-2009
# Posted on: 15-Apr-2009 11:58:58   

Walaa wrote:

This was intensively discussed here: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=15323

So, if I understand it right - there is no solution?? There is no way in selfservicing to determine if the Entity is initialized from Collection or directly via Construcor?

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 15-Apr-2009 12:11:19   

This post proposed a solution.

Bombus
User
Posts: 8
Joined: 15-Apr-2009
# Posted on: 15-Apr-2009 12:40:03   

Walaa wrote:

This post proposed a solution.

I hate it to change templates :-)

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 15-Apr-2009 12:56:11   

Me too, but it's a good thing to have the ability to manupilate it. wink