Fetch dirty entity

Posts   
 
    
kievBug
User
Posts: 105
Joined: 09-Jan-2009
# Posted on: 07-Oct-2010 15:41:46   

Hi guys,

LlblGen allows partial updates for entities, i.e. without fetching entity from the DB. So I can create an entity, set PK and a field(or several) that I want to change, clear IsNew flag and then just send it for saving, and it will be updated correctly.

The problem that I have right now is that there is BL that needs entity fields, that were not fetched. And the question is is there a way to fetch entity and leave all the changes in it? Can LlblGen load it somehow for me? The entity(or the graph) is coming from the presentation layer, I can not really change it, and also I do want to support the partial updates for entities, so it would be great if I can load it.

Is the a way to do this? May be using ExcludeIncludeFieldsList, to exclude changed fields, but I'd like to have Old value(DbValue) for the field too :-)

Any thoughts?

Thanks, Anton

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 07-Oct-2010 22:02:59   

Just to clarify, you want to create the entity, set the PK value and some field values, and then load the remainging fields from the db, without altering the values of the fields that you have already set manually ?

Matt

kievBug
User
Posts: 105
Joined: 09-Jan-2009
# Posted on: 07-Oct-2010 22:20:41   

Yes, that is correct. And also for those fields that are changed, I want to have a DbValue(i.e previous value) after I fetch it.

Anton

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 08-Oct-2010 09:05:19   

You may let the BL fetch the entity from the database (fetching all the fields).

So now it has 2 versions of the same entity, one passed from the UI, and one freshly fecthed from the database.

Now you can loop on the fields of the UI version and check which fields are dirty (IsChanged), and then it should coppy the currentValue of these fields into the currentValue of the corresponding fields on the DB-version entity.

kievBug
User
Posts: 105
Joined: 09-Jan-2009
# Posted on: 08-Oct-2010 15:10:09   

Well, I just thought that LlblGen may have something for it. Because it is natural to have BL as for me, not just saving data to Db, and support for partial entities updates is also an awesome feature.

Anyway, thanks for your help.

Anton

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 09-Oct-2010 03:01:58   

kievBug wrote:

Well, I just thought that LlblGen may have something for it. Because it is natural to have BL as for me, not just saving data to Db, and support for partial entities updates is also an awesome feature.

Not supported. The thing is that this looks weird as it breaks with the normal entity cycle. The workaround Walaa mentioned should be the preferred way in you case.

kievBug wrote:

Anyway, thanks for your help.

You are welcome Anton.

David Elizondo | LLBLGen Support Team