We have an ASP.NET MVC application which uses the EF4's data access layer and we are concerned about its relation We are seeing unexpected behavior in OptimisitcConcurrencyExceptions when we think they should not be thrown.
We have simplified the problem with the following code ...
using System.Linq; Use of the project. Model; Namespace Optimized Consigency {Class Program {Static Zero Main () {Contact firstContact = null; (First firstEntities = new ProjectEntities ()) using {firstContact = (first contact with C in the entity, where c.LastName == "select Smith" c). Single (); } (Var secondEntities = New ProjectEntities ()) {var contact from SecondContact = (contact C from the second entity, where c.LastName == "Smith" c)). Single (); SecondContact.Title = "a"; SecondEntities.SaveChanges (); } First contact. Tight = "b"; (Var use the third antities = new project entity), {var thirdContact = (contact C in the third antitouch where c.LastName == "Smith" select c). Single (); Third contact. Title = First Contact Title; // Clearly set version here third contact Version = first dialog Edition; ThirdEntities.SaveChanges (); }}}} This is a simple version of what happens to our MVC app, but there is a single problem.
When we call Save Changes on the third antitige, I expect an exception and nothing is being thrown.
More interestingly, when we attach to SQL Profiler, we see that the version is being used in that segment, but it used third entity version version (existing one in DB) Going, not the first Entity values are explicitly called SaveChanges, it is clearly set up. Resetting the version to not saving the saved value to the SaveChanges value.
In EDMX, the version is set to define a StoreGeneratedPattern.
Anyone have any idea what's going on here?
This is a problem. Once the column is set to calculated , you can not set its value to the application (you can but it has not been used). Edit: If you load the unit from the database, it is tracked by default with reference. The reference stores its original values The original value snapshot changes are used for conversion tracking, but they are used as the only legitimate sources of the calculation / properties. If you set the calculated property to your unit, the value is not used and the original value is used insted. The workaround is to modify the original value (before you modify anything): using (var reference = new TestEntities ()) {var entityToUpdate = context.MyEntities Single (e => e id == some ID); EntityToUpdate.Timestamp = Entity. Temestamp; ObjectState entry entry = reference ObjectState Manager. GetObjectStateEntry (entityToUpdate); Entry.ApplyOriginalValues (entityToUpdate); // Set modified properties reference. SaveChanges (); } Edit 2: Once you have actually recovered the timestamps and timestamps actually loaded, Just do it in the database instead of doing it.
Comments
Post a Comment