问题
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