我有两节课
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);
}
我想要的是禁用proprices的lazyload(),这样我就可以从数据库中获得产品的所有价格。但是,当我将onetomany更改为:HasMany<ProPrice>(x => x.ProPrices).Not.LazyLoad()
时,它会导致无限循环。我错过了什么?
答案 0 :(得分:1)
我不知道,循环来自何处,但您的双向关联可能会导致此问题。您应该将一侧声明为Inverse()。这只能在ProInfoMap中完成,因为它是与双向关联的一对多关系:
HasMany<ProPrice>(x => x.ProPrices).Inverse().Not.LazyLoad();
试试吧。它可能会消除无限循环。