New Posts New Posts RSS Feed: Problem with AcceptChanges() & RejectChanges() in cache.
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Problem with AcceptChanges() & RejectChanges() in cache.

 Post Reply Post Reply
Author
zbig View Drop Down
Newbie
Newbie
Avatar

Joined: 13-Oct-2012
Posts: 28
Post Options Post Options   Quote zbig Quote  Post ReplyReply Direct Link To This Post Topic: Problem with AcceptChanges() & RejectChanges() in cache.
    Posted: 04-Jan-2014 at 9:57am
Hi,

Windows 8.1; DevForce 2012 7.2.2; EF 6.0.2.

I'm testing Windows Store App.

The scenario is quite simple and, I hope, quite common:
1. The user works with local data for some time (1-3 days), stores data in local file, then synchronizes the local cache with remote database (the cache is deserialized from file) .
2. The user adds, deletes and updates entities.
3. Sometimes the user makes some errors (validation errors for instance) and must reject changes (rejects still local changes).

Please find attached a simple solution (VS 2013, no packages because of the size) which simulates the scenario (all necessary client side code exists in MainPage.xaml.cs class). There are only three entities: User, Role and UserRole (many to many relation).

First I add two Users and two roles (assotiated with those users) into the Entity Manager. Then two lines of code:

await appTestEntityManager.ConnectAsync();
await appTestEntityManager.SaveChangesAsync();

makes synchronization with remote database - database is created, data are stored, relations are OK. Everything works fine.

Lets drop database to be sure, that there is no data there.

When in above scenario following two lines are uncommented:

admin.Password = "bbb";
((IEntity)admin).EntityAspect.AcceptChanges();

after executing .SaveChanges() method, Entity Manager throws an exception:

The INSERT statement conflicted with the FOREIGN KEY constraint "FK_dbo.UserRole_dbo.User_UserId". The conflict occurred in database "AppTestDbContext", table "dbo.User", column 'UserId'

The same error will occur, when changes will be rejected.

So the main question is: How to accept/reject changes of updated entity when user works with local cache only?

Thanks in advance for any advice!

Zbig

AppTest4.zip
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down