讓我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