我已经使用 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
。所以我有一个问题,即不可能使用具有不同DataContext
s 的编译查询。我也不想参加DataContext
会议。
有人想解决我的问题吗?