Making Entity framework implement an interface

前端 未结 4 1785
既然无缘
既然无缘 2020-12-09 14:57

I want to use IoC with Entity framework and Ninject. I figure I need the Generated Entity classes to implement an interface, ICRUD. There\'s a walkthrough that shows how t

相关标签:
4条回答
  • 2020-12-09 15:47

    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.

    0 讨论(0)
  • 2020-12-09 15:48

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

    0 讨论(0)
  • 2020-12-09 15:52

    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

    0 讨论(0)
  • 2020-12-09 16:00

    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.

    0 讨论(0)
提交回复
热议问题