简体   繁体   中英

Entity Framework - entity view?

I'd like to create a "view" at the entity level. That is a view that is implemented in the Entity, not at the database. Is this possible?

Example: We have a table that tracks training videos. Each video is assigned to a particular department. So, for example, when teachers in the Biology department log in they should see only the biology videos.

My thinking is that I can pass the department ID to my context, but then what? How do I tie it to the Video DbSet so it's always used to filter the set?

Or is this even the right approach?

It is not possible. It is possible to make a projection and turn in a function for filtering (which then gets translated into SQL) - but it is not possible to create an object that does look like an Entity and in reality is a EF level view.

You can create a DefiningQuery in your EDMX if you don't mind getting your hands dirty with the raw EDMX. I don't believe this is possible with code first. The Entity Framework tutorial site has a good discussion of DefiningQuery that you should check out.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM