2

我已经使用 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会议。

有人想解决我的问题吗?

4

1 回答 1

1

我发现了我的问题。我需要一个自己的 DataContext 部分类,其中包含我的表和其中的连接。所以,现在我可以使用我编译的查询:)。

于 2014-01-27T13:33:57.740 回答