In Fluent NHibernate, how do you map a list of components?

How do you easily match a list of components in Nhibernate?

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 Entity and InsuranceInformation / Person are components.

If I modify InsuranceInformation to be an entity, I can easily map it to FluentNH Automapper. But when I change InsuranceInformation to a component, it throws a matching exception.

+2
source share
2 answers

The Fluent NHictionaryernate IDictionary with the display of the composite elements shows an example of the display of the component dictionary:

 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(); 

Hope this points you in the right direction.

+5
source

If you use Automapper, you need to say that InsuranceInformation is a component, modifying your IAutomappingConfiguration . Override the IsComponent method and return true for your InsuranceInformation type.

+3
source

Source: https://habr.com/ru/post/1445953/


All Articles