Accessing inherited entities of EF in asp.net

Viewed 63

I'm getting started on EF (6.0) and have a quick question:

I used the model first approach to design an entity model that includes an entity named "Component". I then created several entities that inherited from this base type, such as "VideoCard".

Now in my ASP.net codes, I have access to context.Components, but I cannot seem to directly return context.VideoCards. So if I want to return a list of video cards only, should I use something like

 context.Components.OfType<VideoCard>();

(tried this it seems to work), or is there something else I should know on this topic?

Edit: I realized that this also works:

context.Components.Where(x => x is VideoCard);

Is one of these approaches better than the other?

Thanks in advance for your reply.

1 Answers
Related