New Posts New Posts RSS Feed: DomainModelEntityManager.SaveChanges(IEnumberable entities) doesn't save properly
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

DomainModelEntityManager.SaveChanges(IEnumberable entities) doesn't save properly

 Post Reply Post Reply
Author
monkeyking View Drop Down
Groupie
Groupie
Avatar

Joined: 04-Mar-2009
Location: brisbane
Posts: 68
Post Options Post Options   Quote monkeyking Quote  Post ReplyReply Direct Link To This Post Topic: DomainModelEntityManager.SaveChanges(IEnumberable entities) doesn't save properly
    Posted: 05-Jul-2009 at 6:10pm
DomainModelEntityManager.SaveChanges(IEnumberable entities) only be able to save the added entities and modified entities, but it can't save the deleted entities, but DomainModelEntityManager.SaveChanges() be able to save properly. But we do need DomainModelEntityManager.SaveChanges(IEnumberable entities), because it can save a specific GUI's data.

this is the delete method i'm using, it's able to delete the entities in cache


this is the save method, it works for add and modify, but doesn't work for delete.


 the SaveIndividual might be a bit confusing you i think, acutually it just uses the SaveChanges(IEnumberable entities) method.







Back to Top
GregD View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 374
Post Options Post Options   Quote GregD Quote  Post ReplyReply Direct Link To This Post Posted: 06-Jul-2009 at 1:48pm
The overload of SaveChanges() that takes an IEnumerable works fine with deleted Entities. On the other hand, DevForce automatically removes entities from BindableLists when those entities get deleted. So probably what's happening is that you're passing SaveChanges() a list that already has the deleted entities removed.

So, you need to pass it a list that includes the deleted entities. You can use EntityManager.FindEntities<T>(EntityState.Deleted) to get a list of references to deleted entities of type T; e.g.,

    List<Customer> deletedCustomers = EntityManager.FindEntities<Customer>(EntityState.Deleted) .ToList();

then add those entities to the list you pass to SaveChanges().
Back to Top
monkeyking View Drop Down
Groupie
Groupie
Avatar

Joined: 04-Mar-2009
Location: brisbane
Posts: 68
Post Options Post Options   Quote monkeyking Quote  Post ReplyReply Direct Link To This Post Posted: 06-Jul-2009 at 4:44pm
Thanks GregD, it works :-)

one more question. i find some time i have 'ToList()' method after a query, but some time there is not, in my case, I don't have that 'ToList()', so I just pass the whole query as the parameter of SaveChanges(), so I how can I determine if the 'ToList()' method appear after the query?
Back to Top
GregD View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 374
Post Options Post Options   Quote GregD Quote  Post ReplyReply Direct Link To This Post Posted: 08-Jul-2009 at 8:40pm
Originally posted by monkeyking

Thanks GregD, it works :-)
how can I determine if the 'ToList()' method appear after the query?


In this case, I used ToList() because I wanted the results in a List<Customer>, FindEntities<Customer>() returns an IEnumerable<Customer>, and the compiler can't implicitly convert the latter to the former.

But often a call to ToList() is made primarily to force immediate execution of the query, when you need the results in the cache immediately.  See this blog on LINQ and deferred execution:

     http://blogs.msdn.com/charlie/archive/2007/12/09/deferred-execution.aspx



Back to Top
monkeyking View Drop Down
Groupie
Groupie
Avatar

Joined: 04-Mar-2009
Location: brisbane
Posts: 68
Post Options Post Options   Quote monkeyking Quote  Post ReplyReply Direct Link To This Post Posted: 09-Jul-2009 at 12:07am
'ToList()" is very useful to me when I apply anonymous type. because a list of anonymous type elements is a bit hard to make, I can use 'var query' to load a set of  anonymous type elements from memory, but how can I convert that 'query' to a list to bind with? so if there is a 'ToList()' after query will be very useful in this case, but some time I can't find this method.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down