是否可以强制实体框架生成的属性实现接口? [英] Is it Possible to Force Properties Generated by Entity Framework to implement Interfaces?
本文介绍了是否可以强制实体框架生成的属性实现接口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
示例接口:
public Interface IEntity
Property ID() as Integer
end Interface
我希望我的所有EF对象都可以在那里的主键上实现此接口。
I want all my EF objects to implement this interface on there Primary Keys.
这可能吗?
推荐答案
在CSharp中这似乎很容易做到,但是在VB中专门声明哪些属性/函数/子正在实现该接口:
This seems very easy to do in CSharp but in VB you have to specifically declare which Properties/Functions/Subs are Implementing the Interface:
public Property Id() as Integer Implements IEntity.Id
不幸的是,我不得不翻出设计器文件并修改生成的属性。我最终完全摆脱了生成的文件,现在将模型与所有属性映射都放在单独的类中。
Unfortunately I had to Rip out the designer file and modify the generated properties. I ended up getting rid of the Generated File all together and now keep my Models in separate classes with all of the Attribute mappings.
这篇关于是否可以强制实体框架生成的属性实现接口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文