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

给你一囗甜甜゛ 提交于 2019-12-12 19:58:48

问题


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 virtual 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.


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/4157820/in-fluent-nhibernate-how-do-you-map-a-component-list

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!