I am trying to make use of Unity Framework with Entity Framework. Let me explain the scenario. Let's say I have a Database with 5 tables. I will have 5 interfaces each of them corresponding to one table in Database having each field of table as a member. Now I want my Entity Framework generated classes to implement corresponding table interface. All navigational properties should return objects as interface references. This should allow me to resolve these entities using Unity framework to allow any one to extend EF(data) entities without breaking required codes. Is this possible?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
No there is no extensibility point for resolving entities with IoC container. EF will always handle instance creation of persisted entities. Morover EF mapping must work with classes not interfaces.
You can only handle ObjectMaterialized
event on ObjectContext
and provide some additional initialization of created entities.
You can try to add interfaces by implementing custom T4 template and including some convention (like name of the interface is always I + name of the entity) but still without IoC.