Reputation: 857
I have a problem with one of my queries using linq 2 entites. I'm trying to view the query before it is generated to the db but without any success. I tried using ToTraceString() but couldn't cause the query could not be cast to ObjectQuery. this is my query:
var movies = (from m in watchedRepo.GetAll().Where(c => c.iUserId == userId).ToList()
join f in moviePageViewsRepository.GetAll() on m.iMovieId equals f.iMovieId
group f by new JoinClass { MovieId = f.iMovieId, Points = m.iPoints }
into g
orderby g.Key.Points descending , g.Sum(d => d.iScore) descending
select new JoinClass { MovieId = g.Key.MovieId, Points = g.Key.Points, PageViews = g.Sum(d => d.iScore) }).Skip(skip).Take(take);
if I try to execute it from linq I get an out of memory exception. any ideas please?
Upvotes: 1
Views: 330
Reputation: 39898
The problem is with your ToList()
in the first line of your query. This will immediately fetch all rows from wachtedRepo
with the specified UserId
.
Because your query will then become a hybrid Linq to Entities / Linq to Objects, you can't cast to an ObjectQuery
. Is your query still working when you remove ToList()
?
If you want to see what's really happening in your Sql Server, I would suggest using the Sql Server Profiler tools to view your queries.
Upvotes: 3
Reputation: 137554
Assuming watchedRepo
is the Linq to SQL object representing the database connection
watchedRepo.Log = Console.Error;
All SQL queries will be printed to standard error.
Upvotes: 1