Using SaveEntity Methods

Posts   
 
    
Devildog74
User
Posts: 719
Joined: 04-Feb-2004
# Posted on: 28-Nov-2004 14:42:57   

What would be an example of using this method:


public virtual bool SaveEntity(
   IEntity2 entityToSave,
   bool refetchAfterSave,
   IPredicateExpression updateRestriction,
   bool recurse
);

or this one?


public virtual bool SaveEntity(
   IEntity2 entityToSave,
   bool refetchAfterSave,
   IPredicateExpression updateRestriction
);

Or why and when would you want to use these?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 29-Nov-2004 09:21:46   

When you want to restrict the save process in such a way that for example a given field in the entity to update (it only works with updates) has a given value, so you can implement a concurrency scheme the way you like it.

Frans Bouma | Lead developer LLBLGen Pro
Devildog74
User
Posts: 719
Joined: 04-Feb-2004
# Posted on: 29-Nov-2004 11:00:49   

So for example if we have a table called Employee defined as:

EmpId int identity(1,1) Primary Key, FirstName, LastName, Gender

We could write code so that all employees whose name is Bob would have their gender set to 'M'?

Is that what you are saying?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 29-Nov-2004 11:36:27   

That's functionality provided by UpdateEntitiesDirectly(). simple_smile

SaveEntity() with a restriction is used when you have concurrency rules based on a timestamp column for example, or you only should update a row when the original values aren't changed. You can then construct a filter on these fields and pass it in with the SaveEntity() which then only succeeds if the filter succeeds.

Frans Bouma | Lead developer LLBLGen Pro