Making Entity framework implement an interface

China☆狼群 提交于 2019-11-28 08:55:11

Presumably the generated entity classes are partial classes, correct?

If so, you can just add your own partial class files to specify the interfaces to be implemented - and to provide any actual implementation methods you need. I suspect that will be a lot simpler than changing what gets generated.

The interface implementation is to be added to the T4 template while modifying it. It is not shown in the screenshots but it is mentioned as item 13 that the user has to implement the IValidate interface in the T4 template. Once the implementation is provide, the generated classes would have those implementations too.

User: notes that the generated classes (under the .tt file) implement the IValidate interface as expected

What about making a base class (outside the EntityModel) that all entities derive from (a simple modification in the T4 template file) and implementing the interface in the base class once? It works perfect for me.

It was a while ago, but I did this using a T4 template... see this post: EntityFramework trigger like Auditing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!