In entity framework when you commit a new item it does not get his id updated according to the database. For example:
public class A {
public int Id {get; set;}
public DateTime LastUpdateUtc {get; set;}
}
Now when I add a new A to my repository:
A a = new A();
a.LastUpdateUtc = DateTime.UtcNow;
repo.Add(a);
repo.SaveChange();
a.Id; // still == 0
Even if I search for the eleement in my repository I get an A but the Id is still equal to 0.
A a = repo.Asquerable().OrderByDescending(a => a.LastUpdateUtc ).First();
a.Id; // still == 0
Does someone know how do I tell entity framework to update the Id feild from what the database have compute?
Thanks
Eventually I did make it work by adding the attirbute: