I've created a small WCF Data service, I can Add/retrieve data without any problem.
I've a set on this collection "Household", with all rights:
config.SetEntitySetAccessRule("HouseHold", EntitySetRights.All);
The problem is that I just can't edit:
HouseHold houseHold = entities.HouseHold.Where(h => h.IDHouseHold == varContainingAnExistingId).FirstOrDefault();
houseHold.LastName = "LastName" + DateTime.Now;
entities.SaveChanges();
I don't have any exception, my data is just not updated in the database.
I'm missing something? I should do something more to save my changes?
(My breakpoint stops on the entities.SaveChanges(), so I'm perfec开发者_Python百科tly sure that it runs)
Thank you very much
Edit, I just saw that the ApplyingChanges of my DataServiceContext is set to false, but it's not a property I can edit, is there a link with my problem?
I finally found the solution by exploring context's methods:
There is no change tracking with wcf data service, you then have to specify that the object has changed. This problem happens only when modifying because when adding/deleting we have to call specials methods which put changes flags automatically.
So with my example, the following code is working:
HouseHold houseHold = entities.HouseHold.Where(h => h.IDHouseHold == varContainingAnExistingId).FirstOrDefault();
houseHold.LastName = "LastName" + DateTime.Now;
entities.UpdateObject(houseHold);
entities.SaveChanges();
The UpdateObject is the important change.
have you tried to enable DataServiceConfiguration.UseVerboseErrors?
http://msdn.microsoft.com/en-us/library/system.data.services.dataserviceconfiguration.useverboseerrors.aspx
精彩评论