【发布时间】:2012-08-02 04:45:45
【问题描述】:
我正在开发一个 MVC 应用程序,我在开发它时使用了 EF 4.0。我已经从模型中创建了类。现在,我想为 MVC 制作的每个类添加更多类。
例如。在下面的代码中,我得到了类位置。 现在,我想再创建一个类(部分类)如何覆盖部分类中的属性?
如何做到这一点?
namespace Entities
{
public partial class Location
{
public int Id { get; set; }
public string Name { get; set; }
public string Remark { get; set; }
public string State { get; set; }
public string Region { get; set; }
public string PinCode { get; set; }
public virtual ICollection<Comment> Comments { get; set; }
}
}
【问题讨论】:
-
“覆盖部分类中的属性”是什么意思?
-
我想对部分类中的属性进行一些验证。例如。我想在部分类中添加以下代码 '[StringLength(50, ErrorMessage = "Region can accept maximum 50 characters.")] public string Region { get;放; }'
-
为什么你不能进入你现在的班级?
-
好吧,如果我在当前类中编写它并且如果我再次从模型生成类,那么类会被覆盖并且所有验证都会丢失。而且我的结构还不稳定。所以最好在部分类中编写。
标签: asp.net-mvc model-view-controller entity-framework-4 entity