English 中文(简体)
我的林克声明为什么被两次执行?
原标题:Why is my Linq statement being executed twice?

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,

我的控制者就像你能够做到的那样简单:

var db = MessagingDataContext.Get();
return db.Posts.OrderByDescending(p => p.DatePosted).Skip(pagenumber * pagesize).Take(pagesize);

我的看法同样简单(M_Layout网页有其他标记):

@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?

最佳回答

我的猜测是,@post.User.Name部分正在执行每一记录。 原来的问答结果2

解决这一问题的最佳途径是,在最初的询问中,选择获得你所希望的所有信息(Title, ID和用户名称)。

问题回答

查询是每个用户的用户名。 参数@p0为用户。 如果你检查其价值,你就会发现,每个问题都有所不同。

林克声明没有两次得到执行。 第一个问题来自Linq的发言,我猜测第2和第3次问询来自您的@foreach loop。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签