轉(zhuǎn)自:https://www.cnblogs.com/netfocus/p/5145345.html

image.png
---------------------------分割線------------------------------------------
程序操作上的理解:
值對(duì)象不需要在DbContext里面寫DbSet,比如Address是值對(duì)象,不需要在DbContext里面寫 public DbSet<Address> Addresss { get; set; }
//值對(duì)象(不需要有主鍵)
public class Address
{
#region Properties
// 國(guó)家
public string Country { get; set; }
//省份
public string State { get; set; }
// 市
public string City { get; set; }
public string Street { get; set; }
public string Zip { get; set; }
#endregion
}
使用值對(duì)象的領(lǐng)域:
public class User:AggregateRoot
{
public string UserName { get; set; }
public string Password { get; set; }
public string Email { get; set; }
public string PhoneNumber { get; set; }
public bool IsDisabled { get; set; }
public DateTime RegisteredDate { get; set; }
public virtual Address UserAddress { get; set; }//值對(duì)象
}
生成的數(shù)據(jù)表會(huì)是:

image.png