在流利NHibernate,你如何映射组件列表? [英] In Fluent NHibernate, how do you map a Component list?

查看:111
本文介绍了在流利NHibernate,你如何映射组件列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  public class注册:实体
{
公共虚拟IList< InsuranceInformation> InsuranceInformation {get;组; }
}

公共类InsuranceInformation
{
公共虚拟被保险人{get;组; }
公共虚拟字符串PolicyNumber {get;组; }
公共虚拟字符串InsuranceCompanyId {get;组; }
公共虚拟字符串InsuranceCompanyName {get;组; }
公共虚拟字符串PlanType {get;组; }
公共虚拟字符串GroupNumber {get;组; }
public virtual FamilyRelationships InsuredRelationshipToPatient {get;组; }





这里注册是一个实体和InsuranceInformation / Person是组件。

如果我将InsuranceInformation更改为实体,则可以使用FluentNH Automapper轻松映射。但是,当我将InsuranceInformation更改为组件时,会引发映射异常。

解决方案

复合元素映射的流利NHibernate IDictionary 显示了映射组件字典的示例:

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

希望您能指出正确的方向。


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.

解决方案

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.

这篇关于在流利NHibernate,你如何映射组件列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆