New Posts New Posts RSS Feed: AllInDataSourceAsync with includes
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

AllInDataSourceAsync with includes

 Post Reply Post Reply
Author
cefernan View Drop Down
Groupie
Groupie


Joined: 13-Jul-2012
Posts: 70
Post Options Post Options   Quote cefernan Quote  Post ReplyReply Direct Link To This Post Topic: AllInDataSourceAsync with includes
    Posted: 02-May-2013 at 2:33pm
I got it!

Thank you very much Marcel.
Back to Top
mgood View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 18-Nov-2010
Location: Emeryville, CA
Posts: 583
Post Options Post Options   Quote mgood Quote  Post ReplyReply Direct Link To This Post Posted: 02-May-2013 at 12:33pm
This is normal. The deleted entities are still in the cache of the first EntityManager. Nothing tells it that those entities got deleted. When you call AllInDataSourceAsync you simply get updated data for the entities that still exist, but the deleted entities remain in the cache, because the EntityManager doesn't just assume they were deleted. You can enable change syncing in Cocktail to inform all EntityManagers of the changes you saved in the second ViewModel. This will remove the deleted entities from every EntityManager that holds a copy in its cache. 


As an alternative to the example in the documentation, consider the implementation in TempHire. In addition to the example in the doc, the TempHire implementation also handles the case where in your example you add new entities to the SomethingProperties and want them to appear in the first EntityManager.




Back to Top
cefernan View Drop Down
Groupie
Groupie


Joined: 13-Jul-2012
Posts: 70
Post Options Post Options   Quote cefernan Quote  Post ReplyReply Direct Link To This Post Posted: 02-May-2013 at 6:46am
If I explicity do this below in the first entity manager before call LoadData, SomethingProperties is updated correctly.
UnitOfWork.EntityManager.Clear();
Is it ok?
Back to Top
cefernan View Drop Down
Groupie
Groupie


Joined: 13-Jul-2012
Posts: 70
Post Options Post Options   Quote cefernan Quote  Post ReplyReply Direct Link To This Post Posted: 30-Apr-2013 at 12:32pm
Hi guys,

Let me try to explain my scenario. 

I have two ViewModels working with different unit of works and entity managers.
In the first one, I have a list of entity loaded using this method:
private async Task<BindableCollection<Something>> LoadData()
{
    var repository = UnitOfWork.GetRepository<Something>();
    var entityData = await repository.AllInDataSourceAsync(fetchOptions: f => f.Include(i => i.SomethingProperties));     return new BindableCollection<Something>(entityData);
}
In this first ViewModel, I have a button that calls the second ViewModel (childWindow). In the second ViewModel I'm able to create, edit or delete data from entity Something and SomethingProperties.
So, when deactivate the childWindow I call LoadData() again to refresh my list. As I use AllInDataSourceAsync the update happens perfectly in the entity Something, but the navigation (SomethingPropertiesshows objects that I have deleted (???) with them that I have just created (ok).

PS: Before close the childWindow I have saved changes in the second entity manager. If I check the database, it is everything ok.

What is my mistake?

Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down