0

我有两节课

 public class ProInfo
{
    public ProInfo()
    {
        ProPrices = new List<ProPrice>();
    }
    public virtual Guid ProID { get; set; }
    public virtual string ProCate { get; set; }
    public virtual string Name { get; set; }
    public virtual string Unit { get; set; }
    public virtual string PicName { get; set; }
    public virtual string Memo { get; set; }
    public virtual bool DeleteFlag { get; set; }
    public virtual DateTime LastUpDateTime { get; set; }
    public virtual IList<ProPrice> ProPrices { get; set; }

}

 public class ProPrice
{
    public virtual int Id { get; set; }
    public virtual AreaInfo AreaInfo { get; set; }
    public virtual ProInfo ProInfo { get; set; }
    public virtual Decimal Price { get; set; }


}

映射代码是:

    public ProInfoMap()
    {
        Id(x => x.ProID);
        Map(x => x.DeleteFlag);
        Map(x => x.Name);
        Map(x => x.PicName);
        Map(x => x.ProCate);
        Map(x => x.Unit);
        Map(x => x.LastUpDateTime);
        HasMany<ProPrice>(x => x.ProPrices);


    }

 public ProPriceMap()
   {
       Id(x => x.Id);
       Map(x => x.Price);
       References<ProInfo> (x => x.ProInfo);
       References<AreaInfo>(x => x.AreaInfo);
   }

我想要的是禁用properces 的lazyload(),这样我就可以从数据库中获取产品的所有价格。但是,当我将 onetomany 更改为 this:HasMany<ProPrice>(x => x.ProPrices).Not.LazyLoad()时,它会导致无限循环。我想念什么?

4

1 回答 1

1

我不知道循环的确切来源,但您的双向关联可能会导致这种情况。您应该将一侧声明为 Inverse()。这只能在 ProInfoMap 中完成,因为它是具有双向关联的一对多关系:

HasMany<ProPrice>(x => x.ProPrices).Inverse().Not.LazyLoad();

试试看。它可能会消除无限循环。

于 2012-06-03T20:43:55.923 回答