Placement of extended partial classes in entity framework

混江龙づ霸主 提交于 2019-12-10 14:32:17

问题


Since partial classes have to be in the same namespace is my only option to place them in the same directy as my .edmx? If this is the case I am assuming the file name always has to be different.

Also, is there anything additional that I have to do or do I just create another partial class with the same name in the same directory and add properties/methods to it?


回答1:


The partial classes should be in the same project as the .edmx-file. (the same directory is not required).

Say your Entity Model contains an Entity Person. You can create a new file called Person.partial.cs for your other code. You are free to use any filename for your partial classes. It is only necessary that your partial class is defined in the namespace of the Entity.

namespace MyModel{
   public partial class Person {
      // put your additional logic here
   } 
}


来源:https://stackoverflow.com/questions/30075661/placement-of-extended-partial-classes-in-entity-framework

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