3

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

无论如何,我能够使用 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 分析器中看到产品与需求一起被获取。

4

1 回答 1

1

My idea (Maybe you can try use "HasMany" there is example but you can read something about this):

First class

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;

Second class

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

this.References(x => x.Product).Column("product_id).not.nullable
于 2012-10-18T22:37:56.277 回答