开发者

How can I map a 2 tables (1:many) to a single domain object in fluent NHibernate?

Lets say I have Person (Id, Name) and Address (Id, PersonId, Address, IsPrimary) tables with 1 to 0..2 relation. This both should be mapped to a single domain object Person like this:

public class Person()
{
  public virtual string Name;
  public virtual string PrimaryAddress;
  public virtual string SecondaryAddress;
}

IsPrimary column defines if it is a primary (=true) or secondary (=false) address. So eventually it should be two left joins with additional condition IsPrim开发者_StackOverflow中文版ary=1 or IsPrimary=0.

Is it possible to do this type of mapping in fluent NH? How it might look like?

Thanks!


I would say that in this instance, you're not really doing a one to many mapping. Perhaps it would be better to have your person table more like Person(Id, Name, PrimaryAddressId, OtherAddressId). If you want to do the one to many thing, why not map it one to many then make Primary and Secondary addresses properties that look for the appropriate address in a:

public virtual IList<Address> Addresses { get; set; }

property? I guess that's what makes more sense to me.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜