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 DataContext
s .
Also i don´t want to take the DataContext
in the session.
Have anybody an idea to solve my problem?
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 :).