我有一个非常简单的存储库,我正在使用 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
});
}
有人可以帮忙吗?