
Hi All
I am havinga problem with Entity framework, basically as you can see in the above diagram class A is an abstract class that has two classes that inherit from it B & C.
Each Class has an ID which is not a requirement but was part of the relational structure of the Database design.
I am trying to generate using the EF tools in VS 2008 a model of my Database and then model in the inheritance. I get the model generated fine but the Foreign Keys are still present in the model diagram. I delete those and replace them with the correct inheritance, I also set the Entity Set Names to be the same.
and this is where my problems begin.
The classes do not seem to be working correctly the associations are not working?
Was the removal of the FK correct or should I have left it in place and used the inheritance as well?
I need classes B and C to inherit A in my business layer.
The model doesn’t seem correct and I would be gtreatful for any help in making this model work.
I think the problem is that you have a separate PK and FK that relates your tables. EF expects that the child tables have a single “id” column, in the child tables, that is both the PK and the FK.
Here is a snapshot of an example of a database that I have (this was generated by EF, but you see what I’m talking about):
You’ll see here that
Jobsis the base and the other two derive fromJobs. You’ll see that theIdfield inJobsis the PK, then in the other two tables theIdfield is both a PK as well as a FK back toJobs.Like I said, this model was generated by EF (Model first), but I’m pretty sure this is how EF wants to see things, so I don’t think your database will fit into EF’s inheritance structure.