【发布时间】:2012-12-10 07:54:03
【问题描述】:
我有一个标准的 LINQ 查询:
var list = from x in SomeDataContext.ViewName
where //Rest of where clause
select x;
我想知道是否可以构建动态 LINQ 查询,以便我可以在运行时更改 SomeDataContext.ViewName。
我有大约 5 个不同的视图,所有视图都有执行 where 子句所需的基本列,但其他每个视图都有一些不同的列名。
那么是否可以构建查询,以便我可以在运行时在需要时使用不同的上下文?
例子:
public void SomeMethod()
{
var listA = GetList("DataContext.ViewA");
var listB = GetList("DataContext.ViewB");
var listC = GetList("DataContext.ViewC");
}
public List<EntityObject> GetList(string dataContextName)
{
return (from x in /*HERE I WANT TO USE THE dataContextName*/
where //Rest of where clause
select x).ToList();
}
【问题讨论】:
标签: c# .net linq linq-to-entities entity-framework-4.1