让我EF6项目说[数据库,第一个方法]我有一个名为Address
复杂类型[我只想澄清我的复杂类型没有任何身份,仅仅是一个合并独立数据的汇总,它甚至不负责其自身的持续性]复杂型内DDD项目的数据库,第一个模型
目前我有所有与该地址相关的字段作为地址的组成部分的直接属性,并具有以下自动生成的定义等级:
public class Person
{
public int Id { get; set; }
public string Name { get; set; }
public Nullable<int> Easting { get; set; }
public Nullable<int> Northing { get; set; }
public string Building { get; set; }
public string County { get; set; }
public string PostCode { get; set; }
public string StreetName { get; set; }
public string StreetNumber { get; set; }
public string Town { get; set; }
public string Unit { get; set; }
public string Village { get; set; }
public int CountryId { get; set; }
}
理想情况下,我想有东西喜欢E以下[我每次更新的数据库模型]:
public class Person
{
public int Id { get; set; }
public string Name { get; set; }
public Address Address { get; set; }
}
public class Address
{
public Nullable<int> Easting { get; set; }
public Nullable<int> Northing { get; set; }
public string Building { get; set; }
public string County { get; set; }
public string PostCode { get; set; }
public string StreetName { get; set; }
public string StreetNumber { get; set; }
public string Town { get; set; }
public string Unit { get; set; }
public string Village { get; set; }
public int CountryId { get; set; }
}
我将如何能够拥有所有地址相关字段作为被叫地址聚集现场,当我从数据库(SQL Server 2012)更新我的模型?
据我所知,唯一的出路是修改T4模板。如果您唯一建议的解决方案是T4模板替换,请您向我展示一些采取类似策略的示例项目或提供您自己的版本。
你使用代码优先方法?使用EF6和代码优先方法时,我对复杂类型没有任何问题。前缀为“Address”的列(例如'Address_Easting','Address_Northing','Address_Building')应默认在表“Person”中创建。如果您使用数据库优先方法,那么只需按照地址相关列的命名模式。 – 2014-10-18 21:58:15
我特别提到这是问题标题中的数据库优先模型。 – MHOOS 2014-10-20 08:02:21
您是否尝试将地址属性移动到EF设计器中的复杂类型(http://msdn.microsoft.com/zh-cn/data/jj680147.aspx)? – Chris 2014-10-22 15:51:47