Fluent Nhibernate 映射帮助
域:
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 保存新人员时,除帐户 ID 字段外,所有内容均保存正常。
一个人不需要拥有帐户即可存在。
我做错了什么?
谢谢。
Domain:
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; }
}
Mapping:
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");
}
Issue:
When saving a new person with an account id everything saves OK except for the acccount id field.
A person doesn't need to have an account to exist.
What am I doing wrong?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
HNibernate 不知道如何处理您的 AccountId。在您的 person 对象上,您有一个 Account 和一个 AccountId 属性。我敢打赌,如果您在保存之前将帐户分配给该人,那么一切都会开始工作。
删除该 AccountId 属性。你不需要它。
HNibernate doesn't know what to do with your AccountId. On your person object, you've got an Account and an AccountId property. I'll bet if you assigned the Account to the person before you save it, it'd all start working.
Get rid of that AccountId property. You don't need it.