New Posts New Posts RSS Feed: Asynchronous cascading deletes
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Asynchronous cascading deletes

 Post Reply Post Reply
Author
kpozin View Drop Down
Newbie
Newbie


Joined: 30-Aug-2010
Posts: 4
Post Options Post Options   Quote kpozin Quote  Post ReplyReply Direct Link To This Post Topic: Asynchronous cascading deletes
    Posted: 21-Sep-2010 at 1:25pm
What is the current recommended method for managing asynchronous cascading deletes in Silverlight?

Has this issue in DevForce 2009 been fixed?
Back to Top
sbelini View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 13-Aug-2010
Location: Oakland
Posts: 786
Post Options Post Options   Quote sbelini Quote  Post ReplyReply Direct Link To This Post Posted: 22-Sep-2010 at 2:35pm
 
The simplest way would be pre-loading all dependent objects and then deleting.
 
You could also have it executed on the server (i.e. calling InvokeServerMethod).
 
The example in the post you mentioned still works on DevForce2010 (only a slight minor change needed - AsyncCompletedCallback<> is not present in DevForce2010):
 
 
  AsyncSerialTask.Create<Customer>("DeleteCustomer")
    .AddAsyncAction<AsyncEventArgs>(SetupDeletion)
    .AddAction(args => DoDelete((Customer)args.UserState))
    .Execute(aCustomerToBeDeleted);
 
  private void SetupDeletion(Customer cust, Action<AsyncEventArgs> callback) {
    var list = cust.Orders;
    bool isPending = list.IsPendingEntityList;
    if (isPending) {
      list.PendingEntityListResolved += (o, args) => {
        callback(new AsyncEventArgs(cust));
      };
    } else {
      callback(new AsyncEventArgs(cust));
    }
  }
 
  private void DoDelete(Customer cust) {
    cust.EntityAspect.Delete();
    foreach (var order in cust.Orders.ToList()) {
      order.EntityAspect.Delete();
    }
  }
 
 
Back to Top
pompomJuice View Drop Down
Newbie
Newbie
Avatar

Joined: 29-Jul-2010
Location: ZA
Posts: 28
Post Options Post Options   Quote pompomJuice Quote  Post ReplyReply Direct Link To This Post Posted: 29-Oct-2010 at 5:41am
That is ridiculous.
 
You fetch entities to delete them.  What if you want to delete an entity that contains 100 images? (my situation)
 
There has to be a better way?
 
Back to Top
pompomJuice View Drop Down
Newbie
Newbie
Avatar

Joined: 29-Jul-2010
Location: ZA
Posts: 28
Post Options Post Options   Quote pompomJuice Quote  Post ReplyReply Direct Link To This Post Posted: 29-Oct-2010 at 7:08am
Indeed there is.
 
Drop any potential cascade deletes from the Entity Manager's cache and then delete the entity, the database will take care of the rest. That way the EM wont fail on those updates. Makes sense.
Back to Top
sbelini View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 13-Aug-2010
Location: Oakland
Posts: 786
Post Options Post Options   Quote sbelini Quote  Post ReplyReply Direct Link To This Post Posted: 29-Oct-2010 at 9:41am
pompomJuice,
 
The suggestion I provided is for deleting all entities via DevForce.
Of course you can set the cascading delete in your Database and save the wire traffic.
 
Sorry for the confusion.
 
Silvio.
Back to Top
pompomJuice View Drop Down
Newbie
Newbie
Avatar

Joined: 29-Jul-2010
Location: ZA
Posts: 28
Post Options Post Options   Quote pompomJuice Quote  Post ReplyReply Direct Link To This Post Posted: 01-Nov-2010 at 12:43am

Aah, that makes sense.

 

I also was referring to a slightly different situation.

 

My issue was that if I delete an entity and it happens to have a 1..* NOT NULL parent child relationship with another entity that is set to cascade in the database. Such a delete is not possible unless you remove the 1..* loaded children from devforce, otherwise it deletes the parent and updates the children's FKs to NULL which causes FK exceptions.

 

Hope that makes more sense. ( And saw nothing on this topic in the documentation either? The documentation is very quiet about cascading deletes. )

 

Personally I was hoping that devforce could see that a cascade is set via EF 4.0 and compensate. I was over optimistic.

Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down