NHibernate (Fluent) 延迟加载不起作用

标签 nhibernate fluent-nhibernate fluent-nhibernate-mapping

我正在尝试使用 NHibernate 为一个非常奇怪的数据库生成模型。表本身有仅供显示的主键,所有实际关系都在唯一列上。例如,具有产品 ID 主键和唯一产品名称列的产品表。另一个表 demand 有一个产品名称列,它定义了关系。我知道这种情况并不理想,但它超出了我的控制范围。

无论如何,我能够使用 Fluent NHibrenate 将产品映射到需求,但我似乎无法让实体延迟加载。

public class Demand
{
  public virtual DemandId { get; set; }
  public virtual Product { get; set; }
}

public class DemandMap : ClassMap<Demand>
{
  public DemandMap()
  {
    this.Table("Demand");
    this.LazyLoad();
    this.Id(x => x.DemandId);
    this.References(x => x.Product).PropertyRef(x => x.ProductName).LazyLoad();
  }
}

有没有人知道为什么延迟加载不起作用?我知道这不是因为我可以在 SQL 事件探查器中看到随需求一起提取的产品。

最佳答案

我的想法(也许你可以尝试使用“HasMany”有例子,但你可以阅读一些相关内容):

头等舱

public class Demand
{
  public virtual int DemandId { get; set; }
  public virtual int Product { get; set; }
  public virtual IEnumerable<NewClass> Name {get; set;} 
}

  this.HasMany(x=> x.Product).Column("Product_id").not.nullable;

二等舱

public class NewClass
{
  public virtual Demand Product_id {get; set;}
}

this.References(x => x.Product).Column("product_id).not.nullable

关于NHibernate (Fluent) 延迟加载不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12962766/

相关文章:

nhibernate - 使用 NHibernate 查询

nhibernate - FluentNHibernate,从另一个表中获取 1 列

c# - FluentNhibernate 公式与连接表中的参数进行映射

c# - 流利的 NHibernate : how to map the where clause filter on a ManyToMany

c# - 带左自连接的 NHibernate QueryOver

c# - NHibernate:in() 的反向版本?

c# - 从范围 'x' 引用类型为 'myClass' 的错误变量 '',但未定义

fluent-nhibernate - 对不同数据库模式中的表使用 Fluent-NHibernate

nhibernate - 即使使用 AllDeleteOrphan,FluentNHibernate 也不会删除子实体

c# - NHibernate 更新不工作