2

I have build a web application with mvc 4. First i implemented the application without compiled queries but to increase the performance i want to use compiled queries. But i can´t use the queries because of the DataContext. I have a class for the queries with a lot of methods like:

    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();
    }

The DataContext is created and disposed in the Controller classes. So i have the problem that it isn´t possible to use a compiled query with different DataContexts . Also i don´t want to take the DataContext in the session.

Have anybody an idea to solve my problem?

1 Answer 1

1

I found my problem. I needed an own DataContext partial class with my tables and the connection within. So, now i can use my compiled queries :).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.