开发者

In Fluent NHibernate, how do you map a Component list?

how do you map a Component list in Nhibernate fluently?

  public class Registration : Entity
{
        public virtual IList<InsuranceInformation> InsuranceInformation { get; set; }
     }

public class InsuranceInformation
{
    public v开发者_开发百科irtual Person Insured { get; set; }
    public virtual string PolicyNumber { get; set; }
    public virtual string InsuranceCompanyId { get; set; }
    public virtual string InsuranceCompanyName { get; set; }
    public virtual string PlanType { get; set; }
    public virtual string GroupNumber { get; set; }
    public virtual FamilyRelationships InsuredRelationshipToPatient { get; set; }
 }

Here Registration is an Entity and InsuranceInformation / Person are Components.

If I change InsuranceInformation to be a Entity, I can map it easily with FluentNH Automapper. But when I change InsuranceInformation to a Component it throws a mapping exception.


Fluent NHibernate IDictionary with composite element mapping shows an example of mapping a dictionary of components:

HasMany<CategoryResource>(x => x._resources)
.AsMap<string>("LangCode")
.KeyColumn("EntityID")
.Table("CategoryResources")
.Component(x =>
    {
        x.Map(c => c.Name);
        x.Map(c => c.Description);
    })
.Cascade.All();

Hopefully that will point you in the right direction.


If you're using the Automapper you need to tell it that InsuranceInformation is a component by modifying your IAutomappingConfiguration. Override the IsComponent method and return true for your InsuranceInformation type.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜