【发布时间】:2014-01-27 10:37:40
【问题描述】:
我已经使用 mvc 4 构建了一个 Web 应用程序。首先我在没有编译查询的情况下实现了该应用程序,但为了提高性能,我想使用编译查询。
但由于DataContext,我无法使用查询。
我有一个用于查询的类,其中包含很多方法,例如:
private static Func<DataContext, int, IEnumerable<Information>> _OwnInformations;
public static List<Information> GetOwnInformations(DataContext dataContext, int userId)
{
if (_OwnInformations == null)
{
_OwnInformations = CompiledQuery.Compile<DataContext, int, IEnumerable<Information>>((dc, id) => (
from tm in dc.GetTable<Information>()
where tm.User.Id == id || tm.Author.Id == id
select tm
));
}
return _OwnInformations.Invoke(dataContext, userId).Distinct().ToList();
}
DataContext 在Controller 类中创建和处置。所以我有一个问题,即不可能使用具有不同 DataContexts 的编译查询。
我也不想在会话中使用DataContext。
有人想解决我的问题吗?
【问题讨论】:
标签: c# asp.net-mvc linq-to-sql datacontext linq.compiledquery