DomainModelEntityManager.SaveChanges(IEnumberable entities) doesn't save properly
Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2009
Forum Discription: For .NET 3.5
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=1360
Printed Date: 13-Mar-2025 at 8:32am
Topic: DomainModelEntityManager.SaveChanges(IEnumberable entities) doesn't save properly
Posted By: monkeyking
Subject: DomainModelEntityManager.SaveChanges(IEnumberable entities) doesn't save properly
Date 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.
|
Replies:
Posted By: GregD
Date 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().
|
Posted By: monkeyking
Date 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?
|
Posted By: GregD
Date 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
|
Posted By: monkeyking
Date 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.
|
|