我在我的Entity Framework数据库上下文中禁用了延迟加载。但是仍然存在以下模型的问题:
public class Currency
{
//properties
public ICollection<ConversionRate> ConversionRates{get;set;}
public Currency()
{
ConversionRates = new HashSet<ConversionRate>();
}
}
转换率等级如下:
public class ConversionRate
{
[ForeignKey("FromCurrencyId")]
public Currency FromCurrency { get; set; }
public Guid FromCurrencyId { get; set; }
[ForeignKey("ToCurrencyId")]
public Currency ToCurrency { get; set; }
public Guid ToCurrencyId { get; set; }
}
以下是配置:
///Currency
HasMany(x => x.ConversionRates).WithRequired(x => x.FromCurrency);
HasMany(x => x.ConversionRates).WithRequired(x => x.ToCurrency);
当我使用以下语句获取ConversionRate
时:
var cr = _uow.ConversionRates.Query
.Include(x=>x.FromCurrency)
.Include(x=>x.ToCurrency)
.FirstOrDefaultAsync(x=>x.Id==id);
填充以下集合:
cr.FromCurrency.ConversionRates
cr.ToCurrency.ConversionRates
我在填写馆藏时做错了什么?
答案 0 :(得分:0)
您的ConversionRates集合需要定义为虚拟。 https://msdn.microsoft.com/en-us/data/jj574232.aspx#lazy