delete entities on save

Posts   
 
    
jspanocsi
User
Posts: 145
Joined: 04-Mar-2005
# Posted on: 20-Sep-2012 17:11:16   

is there a way to cache the delete of an entity and then delete it from the collection on a save or something?

this is hard to describe, but basically what we have in our app are parent child forms.

the child entities are in an llbl gen collection on the parent. we use self service.

the user will go and enter a parent and a few child records and save them. at this point everything is ok. the user then decides to delete a child record which i immediately remove from the database using the standard entity.delete. at this point, on some forms, the data now violates business rules. Something like the child record amounts have to add up to the amount on the parent etc. the user can exit the app/close the screen etc, and we have bad data in the db now.

what i want to do is just mark the entity some how, or remove it from the llbl gen collection and then when the user actually saves the screen (IE all validations have passed because they fixed the other child records to match the total now) do the save and delete at the same time.

If i were using EF, i'd flag the child entity for removal out of it's EF collection and then change/add new records etc and none of it would happen until i call savechanges on the context. how do i accomplish this in llbl gen?

Thanks!

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 20-Sep-2012 18:42:42   

Just remove the entities from the collection, don't delete them. Then use the Tracking entity remove actions to delete them later.

jspanocsi
User
Posts: 145
Joined: 04-Mar-2005
# Posted on: 21-Sep-2012 17:02:34   

Ok, i've been playing with this over the last day and have another question. can i do this generically or do i have to know the child collections?

we have a base form that handles all save/deletes/etc for several hundred entities. can i tell the generic entity (Like entitybase or ientity etc) to do this somehow or do i have to know the collections directly? right now we're using ProduceTopologyOrderedList at the parent level and checking all returned items for isdirty to save anything that might be dirty. i'd need to know what collections had removed one also at that point.

thanks

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 22-Sep-2012 07:22:59   

Please elaborate more with an example, I don't know what are you trying to achieve.

If you have a collection with tracked removed elements then you can pass it to a form that receive it in a generic way, if that is what you mean.

David Elizondo | LLBLGen Support Team
jspanocsi
User
Posts: 145
Joined: 04-Mar-2005
# Posted on: 24-Sep-2012 15:35:59   

so basically we have a base form that handles all our simple data entry forms. the base handles deletes/saves/searches etc. the inherited forms from this form have the controls on it and the actual hard typed llbl gen entities. the base form just has an entity of type EntityBase that's protected. the inherited forms actually fill that entity out with a hard typed one.

at base level i don't know what i'm dealing with. might be a customer with orders and order lines, or a purchase order with order lines and order accounts etc. we have hundreds of forms like this.

when we do a save, we do the topography list to get a list of entities and we see which ones are dirty and then save them individually. in the case of a customer with orders and order lines, a single order and 2 lines might be dirty etc. the save knows that generically and then saves just those 3 entities.

is there a way to know that an entity has a orders collection that has a tracking collection attached to it or do i have to know it's a customer entity with an orders collection to get the tracking info?

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 25-Sep-2012 00:28:17   

So now you are speaking about tracking removals of entities from child/related collections. Right?

How many levels deep this can go?

jspanocsi
User
Posts: 145
Joined: 04-Mar-2005
# Posted on: 25-Sep-2012 14:14:07   

yes, tracking removals. most of them are one level deep but there are a couple spots that go 2 levels. i'm pretty sure we don't have 3 levels anywhere.

the 2 level ones are usually like customer->order->order lines etc.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 25-Sep-2012 20:21:55   

To do this generically, cast the entity to (IEntity) and call GetMemberEntityCollections() This should return a list of EntityCollections related to this entity. loop on them and check the removedEntitiesTracker collection if not null and if the length is more than Zero, then you have something to take care of.

You can recursively call the above routine, on entities inside each collection.

jspanocsi
User
Posts: 145
Joined: 04-Mar-2005
# Posted on: 25-Sep-2012 22:31:23   

Ah cool, ty, i'll try that.