Override Entity Framework Entity Property

心不动则不痛 提交于 2019-12-05 10:11:49

You unfortunately can't change it like that. You have to create a metadata class and add the metadata attributes to that class. See below link:

http://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations.metadatatypeattribute.aspx

Have a look at this link to see some issues with generating a metadata class, what I normally do is if I change something I just regenerate the metadataclass by adding a new service and deleting the service afterwards and then merge the two keeping my old changes and keeping the newly added entities.

You cannot unfortunately add any annotations to the properties generated in the POCO.

A possible workaround is to modify the TT template to add the custom annotation that you want for the given property+entity that you want to target only.

I had the same issue in a previous project when I wanted to use the Enterprise Library to implement validation. I ended up creating a partial class and writing methods decorated with annotations instead.

In your case, you can try creating in a partial class a property (with a different name) that returns the EF entity property with an annotation on top.

I believe you have to mark your property as partial as well.

Actually I think you also will want to remove the override (because you aren't overriding a parent property.)

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