【发布时间】:2009-11-23 08:14:38
【问题描述】:
我正在使用一个非常简单的存储库,使用的是 VS2010 Beta 2 附带的 Entity Framework v4。
我正在尝试动态包含 Include 方法,如果用户有选择地要求它。
例如。
Public IQueryable<Foo> GetFoos(bool includeBars)
{
var entites = new Entities("... connection string ... ");
var query = from q in entities.Foos
select q;
if (includeBars)
{
// THIS IS THE PART I'M STUCK ON.
// eg. query = from q in query.Include("Bars") select q;
}
return (from q in query
select new Core.Foo
{
FooId = q.FooId,
CreatedOn = q.CreatedOn
});
}
有人可以帮忙吗?
【问题讨论】:
标签: .net entity-framework eager-loading