如何在不影响所有其他模型 类 的情况下更新 .edmx 文件?
how to update .edmx file without effecting all the other model classes?
如何在不影响所有其他模型 classes 的情况下更新 .edmx
文件?
当我更新 edmx
文件时,它会重新创建所有其他 classes,这对我来说是个问题,因为我对其他 classes 进行了一些更改,所以如何才能我修改它不影响其他 classes.
例如,这是我的 classes
public partial class company
{
public company()
{
this.Departments = new HashSet<department>();
this.CustomersOfTheCompany = new HashSet<company_customers>();
this.CompaniesTheCompanyCustomerFor = new HashSet<company_customers>();
this.CustomerProjectDetails = new HashSet<cus_pro_connector>();
this.CompanyAsSupplier = new HashSet<company_suppliers>();
this.CompanyAsCustomer = new HashSet<company_suppliers>();
this.Tickets = new HashSet<oneTimeAuthenticationTicket>();
}
[Required(ErrorMessage = "Company name is required")]
[StringLength(200, MinimumLength = 3, ErrorMessage = "Length Of The Company Name Should Be More Than Three Letters")]
public string CompanyName { get; set; }
[Required]
[EmailAddress(ErrorMessage = "Invalid Email Address")]
public string Email { get; set; }
[Required]
public int Country { get; set; }
public int company_id { get; set; }
public string Logo { get; set; }
public string Description { get; set; }
private CompanyDTO _CDTO = new CompanyDTO();
public CompanyDTO CDTO { get { return this._CDTO; } set { this._CDTO = value; } }
public virtual ICollection<department> Departments { get; set; }
public virtual country CountryOfTheCompany { get; set; }
public virtual ICollection<company_customers> CustomersOfTheCompany { get; set; }
public virtual ICollection<company_customers> CompaniesTheCompanyCustomerFor { get; set; }
public virtual ICollection<cus_pro_connector> CustomerProjectDetails { get; set; }
public virtual ICollection<company_suppliers> CompanyAsSupplier { get; set; }
public virtual ICollection<company_suppliers> CompanyAsCustomer { get; set; }
public virtual ICollection<oneTimeAuthenticationTicket> Tickets { get; set; }
}
所以当我修改 .edmx 时,class 属性将不再可用。
重新生成文件时无法保留对生成文件的编辑。如果您需要将属性应用于生成的代码,有一个 MetadataType 机制允许您在另一个部分 class.
中指定验证属性
有关这方面的更多信息,请参阅 this other answer or MSDN。
我不明白你的例子 - 但我会在这里解释:
假设您有以下实体模型:
User.cs
看起来像这样:
public partial class User
{
public User()
{
this.UserWindows = new HashSet<UserWindow>();
}
public int UserId { get; set; }
public string UserName { get; set; }
public string Password { get; set; }
public virtual ICollection<UserWindow> UserWindows { get; set; }
}
添加一个新文件并将其命名为 Extensions.cs
,然后在此文件中创建一个新的部分 Class:
然后你可以给这个添加属性 Class:
public partial class User
{
public int NewUserId { get; set; }
}
每当您创建一个新用户对象时,您都会看到您的新属性:
同样,您可以为 UserWindow.cs
执行此操作
Extensions.cs:
public partial class User
{
public int NewUserId { get; set; }
}
// Similarly you can do
public partial class UserWindow
{
public string MyNewProperty { get; set; }
}
然后
如何在不影响所有其他模型 classes 的情况下更新 .edmx
文件?
当我更新 edmx
文件时,它会重新创建所有其他 classes,这对我来说是个问题,因为我对其他 classes 进行了一些更改,所以如何才能我修改它不影响其他 classes.
例如,这是我的 classes
public partial class company
{
public company()
{
this.Departments = new HashSet<department>();
this.CustomersOfTheCompany = new HashSet<company_customers>();
this.CompaniesTheCompanyCustomerFor = new HashSet<company_customers>();
this.CustomerProjectDetails = new HashSet<cus_pro_connector>();
this.CompanyAsSupplier = new HashSet<company_suppliers>();
this.CompanyAsCustomer = new HashSet<company_suppliers>();
this.Tickets = new HashSet<oneTimeAuthenticationTicket>();
}
[Required(ErrorMessage = "Company name is required")]
[StringLength(200, MinimumLength = 3, ErrorMessage = "Length Of The Company Name Should Be More Than Three Letters")]
public string CompanyName { get; set; }
[Required]
[EmailAddress(ErrorMessage = "Invalid Email Address")]
public string Email { get; set; }
[Required]
public int Country { get; set; }
public int company_id { get; set; }
public string Logo { get; set; }
public string Description { get; set; }
private CompanyDTO _CDTO = new CompanyDTO();
public CompanyDTO CDTO { get { return this._CDTO; } set { this._CDTO = value; } }
public virtual ICollection<department> Departments { get; set; }
public virtual country CountryOfTheCompany { get; set; }
public virtual ICollection<company_customers> CustomersOfTheCompany { get; set; }
public virtual ICollection<company_customers> CompaniesTheCompanyCustomerFor { get; set; }
public virtual ICollection<cus_pro_connector> CustomerProjectDetails { get; set; }
public virtual ICollection<company_suppliers> CompanyAsSupplier { get; set; }
public virtual ICollection<company_suppliers> CompanyAsCustomer { get; set; }
public virtual ICollection<oneTimeAuthenticationTicket> Tickets { get; set; }
}
所以当我修改 .edmx 时,class 属性将不再可用。
重新生成文件时无法保留对生成文件的编辑。如果您需要将属性应用于生成的代码,有一个 MetadataType 机制允许您在另一个部分 class.
中指定验证属性有关这方面的更多信息,请参阅 this other answer or MSDN。
我不明白你的例子 - 但我会在这里解释:
假设您有以下实体模型:
User.cs
看起来像这样:
public partial class User
{
public User()
{
this.UserWindows = new HashSet<UserWindow>();
}
public int UserId { get; set; }
public string UserName { get; set; }
public string Password { get; set; }
public virtual ICollection<UserWindow> UserWindows { get; set; }
}
添加一个新文件并将其命名为 Extensions.cs
,然后在此文件中创建一个新的部分 Class:
然后你可以给这个添加属性 Class:
public partial class User
{
public int NewUserId { get; set; }
}
每当您创建一个新用户对象时,您都会看到您的新属性:
同样,您可以为 UserWindow.cs
Extensions.cs:
public partial class User
{
public int NewUserId { get; set; }
}
// Similarly you can do
public partial class UserWindow
{
public string MyNewProperty { get; set; }
}
然后