【问题标题】:FluentNHibernate one-to-one MappingFluentNHibernate 一对一映射
【发布时间】:2012-01-21 01:08:56
【问题描述】:

我有 3 张桌子:

表:公司,列:ID、名称


表:用户,列:Id、Name、CompanyId


表:CompanyOwnerInfo,列:Id、CompanyId、OwnerName.....


UserCompanyOwnerInfo 表中的

CompanyId 列都映射到 Company.Id

我的问题是如何在不涉及 Company 表的情况下为 UserCompanyOwnerInfo 表创建一对一映射?因为当我使用 User 对象来获取 CompanyOwnerInfo 时,没有必要加入 Company 表?

【问题讨论】:

    标签: nhibernate fluent-nhibernate mapping one-to-one


    【解决方案1】:
    public UserMap()
    {
    
        References(x => x.Company, "CompanyId");
    
        References(x => x.CompanyOwnerInfo, "CompanyId")
            .PropertyRef(compOwner => compOwner.Company)
            .Fetch.Join()
            .Not.LazyLoad()   // if needed
            .ReadOnly();      // important otherwise you have Exception on save because both References want to write to the same column
    }
    

    【讨论】:

      猜你喜欢
      • 2011-08-25
      • 1970-01-01
      • 1970-01-01
      • 2012-03-14
      • 1970-01-01
      • 2015-09-09
      • 2014-10-03
      • 2010-11-27
      • 1970-01-01
      相关资源
      最近更新 更多