0

I have entity A. Entity B inherits entity A. For entity B there are o propertis generated by entity framework for accessing it's content. How can access entity B?Do I have to provide my own methods, or can I force EF to cretae them?

what I do is: B inhirits A context.A - have access to entity A

but context.B does not exist. methods are not generated for accessing entity B.

1 Answer 1

2

When you run queries on context.A it will return entities from whole inheritance hierarchy. So the result of context.A.ToList() will be all As and Bs. If you want to query only derived type you can use context.A.OfType<B>().ToList()

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

2 Comments

please tell me is it a bad practice to use OfType? IS this usage of refflection bad for perfomance?
It doesn't use reflection and it is absolutely correct approach.

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.