Closed GoogleCodeExporter closed 8 years ago
I find this problem is because EF 4.1 will cache DbSet's DbCommandDefinition,
so when the 2nd time show the page, it will use the profile of last time.
CreateDbCommandDefinition is only called at first time.
So, the statement as below will throw the exception:
return View(ctx.Posts);
If change DbSet to IQueryable as below, it will not throw the exception:
return View(ctx.Posts.Select(p=>p));
I wonder if there is some way to fix the problem?
Original comment by tocha...@gmail.com
on 19 Jul 2011 at 9:13
I find another condition that will fire the exception.
that is when EF need iterate virtual (lazy-loading) ICollection. For example
@foreach (var tag in post.Tags)
{
<li>@tag.Name </li>
}
Original comment by tocha...@gmail.com
on 19 Jul 2011 at 9:59
I bet it calls .Connection= on the command ... we could set
profiler=MvcProfiler.Current at that point.
Original comment by sam.saff...@gmail.com
on 19 Jul 2011 at 10:55
on second thought, I am not sure about this ... reusing db commands is really
dangerous ...
Original comment by sam.saff...@gmail.com
on 19 Jul 2011 at 11:16
I had a repro ... and I think I sorted this one out now. command reuse is risky
but I assume they "check it out" internally so you do not have multiple
consumers setting connection on the same object.
Original comment by sam.saff...@gmail.com
on 20 Jul 2011 at 12:35
Really perfect!
Original comment by tocha...@gmail.com
on 20 Jul 2011 at 2:02
Original issue reported on code.google.com by
tocha...@gmail.com
on 19 Jul 2011 at 7:56Attachments: