This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
I have a project where my DataGridView is being refreshed at certain intervals due to the fact entities may change frequently in the tables by a server service. To maintain selections and keep the user up to date, informed, and the interface from becoming jumpy I pull only changes that have occurred in the table since the last refresh time and use UnitOfWork.Import This works fine and my grid updates, but during the next save() operation that takes place by user interaction on a non-related row the entity that was merged is also getting it's state saved back to the database even though the user did not make any changes to that specific record. I assume this is because the Import operation is also setting the EntityState to modified since it found a matching Id, but I would like to be able to prevent this as it is unnecessary in my situation. An example of what I would like to see would be a method UnitOfWork.Import Hopefully this makes sense and any help would be appreciated. thanks, Bobby Ross |
|
|
If you are seeing an EntityState of Modified after calling .Import() it will be because there has been a change applied (e.g. a property change occurs when the data is being merged), so the entity has been modified. Import will try and load an existing entity by Id first via a FindById call so if the entity was already previously loaded it will use the in-memory copy otherwise it will be loaded from the database. Are you loading your "refreshed" copies from a second UOW and then importing them into your original one?
|
|
|
I am using a second unit of work due to caching issues. |
|
|
I imagine the property change is being picked up because the original copy is still in the UnitOfWork you are importing into. Try detaching the existing entity prior to importing the new one by calling UnitOfWork.Detach.
|
|