Click here to Skip to main content
15,605,787 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I'm currently messing around with EF and have come across a scenario where I want the entities in my model to implement interfaces. Effectively I'm working on a system that has a core database, connected to which is a database full of restricted views (possibly not the best implementation but there's no way I can currently get this changed).

I effectively want to create interfaces for the entire database so that I can use the normal and restricted databases interchangably.

I've added an EntityObject generator and changed the template so that the code that is produced references interfaces rather than concrete items, but when I try to run a test, I get an error stating that mapping and metadata information can't be found for the EntityType.

I've got a feeling that the EF model doesn't support inheritance and that it's only a concrete implementation of the underlying data.

Can anyone confirm if this is true or give me some indication of how I could best proceed with this?

Thanks in advance
Posted

What you are talking about is Persistence Ignorance, and is a feature that is supported in EF. Effectively, you want to convert the entity into a POCO. You should read this[^] for details on how to do this.
 
Share this answer
 
CSS
Alternatively, you can download my project on Codeplex. I have a working example that you can copy.
https://entityinterfacegenerator.codeplex.com/

It generates the interface files that you need for IoC purposes.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900