我已经使用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
。
有人想解决我的问题吗?
我发现了我的问题。我需要与表格和内部的连接一起使用自己的DataContext部分类。因此,现在我可以使用我的编译查询:)。