我使用以下功能从存储库中获取“粘贴”,但我无法访问在获取粘贴时应包含的对象。(粘贴.FilterGroup.Ads)。
我的存储库功能:
public T Find<T>(Expression<Func<T, bool>> predicate) where T : class
{
return Context.Set<T>().FirstOrDefault<T>(predicate);
}
在我的代码中我试试这个。
oPaste = _repository.Find<Paste>(x => x.PasteID == oPaste.PasteID);
if (oPaste.FilterGroup != null)
{
_log.Debug("FilterGroup: " + oPaste.FilterGroup.Name);
if (oPaste.FilterGroup.Ads != null && oPaste.FilterGroup.Ads.Count() > 0)
{
_log.Debug("FINALLY");
}
else
{
_log.Debug("Paste " + oPaste.PasteID + " has no ads");
}
}
else
{
_log.Debug("Paste " + oPaste.PasteID + " has no filtergroup");
}
编辑: 粘贴类包含
public virtual FilterGroup FilterGroup { get; set; }
FilterGroup 类包含
public virtual IEnumerable<Ad> Ads { get; set; }