1

I have a requirement to build a slightly unusual data model, but I'm having trouble persuading Entity Framework Code First to map it for me.

I have two entities - 'A' and 'B'.

'B' is a type of 'A', which is why I'm trying to get inheritance working.

However, multiple versions of 'B' may exist.

I would like to model this by having a shared ID column in each of the tables for 'A' and 'B', but for 'B' to also have a 'Version Number' field which makes a combined key with the ID.

So - this would be a one-to-many inheritance type of arrangement.

Ultimately the goal for this would be to be able to retrieve a specific 'B' entity and for it to also contain all of the properties and methods of the related 'A' entity without having to go via another object.

Any ideas would be great.

Thanks, Chris

1 Answer 1

1

Inheritance in EF is always one-to-one. If you have one-to-many you must handle it as relation or build your own intermediate layer which will hide EF implementation by your own domain model (which will take related objects from EF and create your own inherited object).

Sign up to request clarification or add additional context in comments.

1 Comment

I suspected that may be the case - thanks for confirming!! :o)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.