I am working on an internal message system. I have the mvc mini profiler hooked up, and it is showing me some statements are executed twice, and I can’t figure out why,
My controller is as simple as you can get:
var db = MessagingDataContext.Get();
return db.Posts.OrderByDescending(p => p.DatePosted).Skip(pagenumber * pagesize).Take(pagesize);
and my view is just as simple (my _Layout page has the rest of the markup):
@foreach (var post in Model)
{
<div class="post">
<p>
@Html.ActionLink(post.Title, "View", "Posts", new { postid = post.Id}) by @post.User.Name
</p>
</div>
}
So why would get_User be executed twice?

My guess is because the
@post.User.Namepart is executing for each record. Did the original query return 2 results?Best way to fix this is in the original query do a select to get all the info you want (Title, ID and Username).