简体   繁体   中英

Can you do entity inheritance in EF on an entity that is mapped to stored procedures?

I have a question about inheritance in Entity Framework 4. We are using a database-first approach and would like to restructure our model to use inheritance. Here is a white board mock up of the hierarchy we would like to use in our model.

Image 1

In case those scribbles are not very readable, it's something like this.

USER <- PROVIDER
USER <- VENDOR
PROVIDER <- EMPLOYEE

So USER is the base class for providers and vendors. And employee then inherits from provider.

I found a couple great articles describing Table-Per-Hierarchy inheritance and Table-Per-Type inheritance.

They seem simple enough but both ways require an entity to be mapped to a table or tables. What if you have an entity that is mapped entirely to stored procedures?

Image 2

Is it still possible to do inheritance in EF even if an entity is mapped to stored procedures? How would that look? What kinds of stored procedures would we need to have to accomplish this?

If it's possible we really just need pointed in the right direction.

I have searched and searched and finally arrived at the conclusion that it is not possible to do inheritance with entities that are mapped to stored procedures. So unless someone can prove otherwise, I'm marking this as the answer.

I am using a completely stored procedure mapped repository architecture in my MVC project. In that we are not using the entity framework, instead of that we use Microsoft Enterprise Library . We are using the methods from it. From my experience, The repository contains only methods for data manipulation using stored procedures. The Tables are mapped to Models. There are ViewModels which are custom Model classes for handling properties which are defined as custom in the project. There is one service layer to separate the Controllers and Repositories. So I think you can adopt the method of repository mapped entirely to stored procedures

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