【发布时间】:2017-02-20 12:06:26
【问题描述】:
我添加了以下扩展方法
/// <summary>
/// Provides a statically typed interface for db includes
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="set">The set.</param>
/// <param name="includes">The includes.</param>
/// <returns>DbSet<T>.</returns>
public static DbSet<T> Include<T>(this DbSet<T> set, params Expression<Func<T, object>>[] includes) where T : class
{
if (includes != null)
{
foreach (var expression in includes)
{
set.Include(expression);
}
}
return set;
}
这是基于我在这里找到的存储库代码
https://github.com/carbonrobot/FullStackEF/tree/master/src
但是,当我将其与以下内容一起使用时
public ServiceResponse<Town> Get(int id)
{
Func<Patient> func = delegate
{
using (var context = _contextFactory())
{
return context.Get<Town>(id, x => x.County);
}
};
return this.Execute(func);
}
其中城镇类包含县实体。
当它调用扩展方法而不是基础包含时,我得到了一个无限循环?
有什么想法我在这里做错了吗?
【问题讨论】:
标签: linq entity-framework-5 linq-to-objects c#-5.0