New Posts New Posts RSS Feed: Deleting entities using another collection
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Deleting entities using another collection

 Post Reply Post Reply
Author
robertg View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 15-Mar-2011
Location: California
Posts: 87
Post Options Post Options   Quote robertg Quote  Post ReplyReply Direct Link To This Post Topic: Deleting entities using another collection
    Posted: 26-May-2011 at 4:44pm
Hey, Albert just filled me in a little on your project, and I understand why you'd want to use the original described behavior if it's a big conversion project. It sounds like you have the information you need now, but if there's anything else, please let us know.
Back to Top
robertg View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 15-Mar-2011
Location: California
Posts: 87
Post Options Post Options   Quote robertg Quote  Post ReplyReply Direct Link To This Post Posted: 26-May-2011 at 4:00pm
It's not quite the same thing... if you're extending the entites so that you can use them to track their own state, you never have to worry about having extraneous copies of them, or merging anything. You'd just have one EM, and can thus keep it simple.
Back to Top
Randar View Drop Down
Newbie
Newbie
Avatar

Joined: 13-May-2011
Location: Toronto
Posts: 23
Post Options Post Options   Quote Randar Quote  Post ReplyReply Direct Link To This Post Posted: 26-May-2011 at 3:51pm
Hmmm...wouldn't that accomplish the same thing as just keeping them in a list?  If I had a flag, I would have to keep them around for a while.  The problem is the time between the flagging and the call to SaveChanges may be some time apart.  I have an entity that was associated with with one EM and trying to delete it a different EM.  Are you saying that is possible and happens by default?

If so, I have to look through my code again and find out why they are not actually being deleted.
Back to Top
robertg View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 15-Mar-2011
Location: California
Posts: 87
Post Options Post Options   Quote robertg Quote  Post ReplyReply Direct Link To This Post Posted: 26-May-2011 at 3:45pm
Randar,
 
Have you considered adding a property to the entity with a partial class, and using that property to track entities you want to delete? Then, when it's time to save your changes, you can first run a query for that property, and delete each of the entities that match it. It's much more straight-forward than storing information about those entities in another object.
 
-- Robert
Back to Top
Randar View Drop Down
Newbie
Newbie
Avatar

Joined: 13-May-2011
Location: Toronto
Posts: 23
Post Options Post Options   Quote Randar Quote  Post ReplyReply Direct Link To This Post Posted: 26-May-2011 at 3:28pm
What I'm trying to do is:
1) Keep track of the entities that need to be deleted in a List(Of T As IdeaBlade.EntityModel.Entity)
2) When the person actually hits the "save", take that list and actually delete the entities along with a bunch of other data.

I tried to create a new EntityManager and then take my list of entities and called .EntityAspect.Delete on them.  No big surprise, but they didn't get deleted because they originally belonged to a different EM.

Is there a way I can take those entities and attach them to the new EM and then delete them when I hit SaveChanges?  I'm just trying to not re-retrieve them from the server if I can.

I hope I explained myself well enough.

In case you ask, there are reasons, that would take a while to explain, but I can't just flag the entity at the time of deletion using .EntityAspect.Delete.  I have to keep track of the list.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down