gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 06:22:16 27 4
gpt4 key购买 nike

我正在尝试使用 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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com