Entity Framework - Id of loaded entity not being assigned?

Ok it is not problem with inheritance as I initially thought - the inheritance will work. This is most probably combination of two problems: Id is generated in the database but EF doesn't know about them. Both SSDL and CSDL part of EDMX should define Id with StoreGeneratedPattern.

Identity This will force EF to reload Id when entity is inserted I believe you are using same context instance for saving entity and calling the query. Now you meet identity map pattern Despite the data retrieved from the query EF will use instance internally stored in its per-context cache. Because of the first problem the cached instance has Id with default int value = 0.

Ok it is not problem with inheritance as I initially thought - the inheritance will work. This is most probably combination of two problems: Id is generated in the database but EF doesn't know about them. Both SSDL and CSDL part of EDMX should define Id with StoreGeneratedPattern.Identity.

This will force EF to reload Id when entity is inserted. I believe you are using same context instance for saving entity and calling the query. Now you meet identity map pattern.

Despite the data retrieved from the query EF will use instance internally stored in its per-context cache. Because of the first problem the cached instance has Id with default int value = 0.

I can't quite believe that EF would interfere so much with my domain design decisions. I use this pattern with N and NH doesn't even so much as raise an eyebrow. – David May 17 at 18:25 When I change the class so that it doesn't extend Entity and add the Id property to the class directly, I still get exactly the same problem.

– David May 17 at 18:43 Are you using the same context instance for saving and loading? – Ladislav Mrnka May 17 at 18:45 I'm not saving. This particular context instance is simply loading a list of Person instances for display in a list.

– David May 18 at 10:48 I like your thinking by the way, but the row has been in the database for ages, I'm now just trying to work out how to load it up! – David May 18 at 10:50.

Id is generated in the database but EF doesn't know about them. Both SSDL and CSDL part of EDMX should define Id with StoreGeneratedPattern.Identity. This will force EF to reload Id when entity is inserted.

I believe you are using same context instance for saving entity and calling the query. Now you meet identity map pattern. Despite the data retrieved from the query EF will use instance internally stored in its per-context cache.

Because of the first problem the cached instance has Id with default int value = 0.

Ok it is not problem with inheritance as I initially thought - the inheritance will work. This is most probably combination of two problems.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions