1
public class Account
{
public virtual int AccountId { get; set; }
public virtual int UserId { get; set; }
public virtual string HostName { get; set; }
public virtual DateTime CreatedOn { get; set; }
public virtual bool Deleted { get; set; }
}
public class Person
{
public Person()
{
PersonRoles = new List<PersonRole>();
}
public virtual int PersonId { get; set; }
public virtual Guid PersonGuid { get; set; }
public virtual string FirstName { get; set; }
public virtual string Surname { get; set; }
public virtual string Email { get; set; }
public virtual string Password { get; set; }
public virtual string SaltKey { get; set; }
public virtual int PersonType { get; set; }
public virtual DateTime CreatedOn { get; set; }
public virtual bool Deleted { get; set; }
public virtual bool Active { get; set; }
public virtual int? AccountId { get; set; }
public virtual ICollection<PersonRole> PersonRoles { get; private set; }
public virtual Account Account { get; set; }
}
映射:
public AccountMap()
{
Id(x => x.AccountId, "AccountId").Column("AccountId");
Map(x => x.UserId);
Map(x => x.HostName);
Map(x => x.CreatedOn);
Map(x => x.Deleted);
Table("crm_accounts");
}
public PersonMap()
{
Id(x => x.PersonId).Column("PersonId");
Map(x => x.PersonGuid);
Map(x => x.FirstName);
Map(x => x.Surname);
Map(x => x.Email);
Map(x => x.Password);
Map(x => x.SaltKey);
Map(x => x.PersonType);
Map(x => x.CreatedOn);
Map(x => x.Deleted);
Map(x => x.Active);
HasManyToMany<PersonRole>(x => x.PersonRoles)
.ParentKeyColumn("RoleId")
.ChildKeyColumn("PersonId")
.Cascade.All()
.Table("crm_people_roles_mapping");
//Map(x => x.AccountId);
References(x => x.Account, "AccountId").Column("AccountId");
Table("crm_people");
}
問題:
當保存一個新的人與一個帳戶ID一切節省除了acccount id字段確定。
一個人不需要有一個帳戶存在。
我在做什麼錯?
謝謝。
當你說擺脫AccountId財產,你的意思是在域?編輯:啊,懂了,謝謝。從域中刪除,似乎正在工作。 – izip
是的。您已擁有帳戶資源並且擁有一個ID。根對象上的Id是多餘且令人困惑的。 –
嘿,別忘了提高我的驚人答案。 :) –