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
また、セッションに参加したくありません。
私の問題を解決するアイデアはありますか?