因为没有荣幸 [英] orderby not honored

查看:121
本文介绍了因为没有荣幸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 

.NET 4,EF4,VS2010,C#WinForms,XP SP3。

.NET 4, EF4, VS2010, C# WinForms, XP SP3.

这是该模型的图片对于我正在使用的查询。

Here's a picture of the model for the queries I'm using.

 

在修改我的查询并不断检查它与SQL分析器的功能之后,我差不多完成了。  ;我只是需要它来遵守orderby语句,它不是出于某种原因而做的。感谢

提示22 - 如何真正包括
以使包含再次工作!

After playing around with modifying my query and constantly checking what it's doing with the SQL profiler, I'm almost done.  I just need it to honor the orderby statement, which it's not doing for some reason. Thanks to Tip 22 - How to make Include really Include for getting the Include working again too!

这是我得到的Linq to Entity查询:

Here is the Linq to Entity query I've got:

 


var results = ((from label in Context.Labels             
        from f in label.Label_Field
        orderby label.LabelName
        where label.DeleteInd == false &&
        label.Facility.Name == Facility &&
        (label.LabelName.Contains(txtFind.Text) ||
        f.FieldText.Contains(txtFind.Text))
        select label) as ObjectQuery<MySite.LabelMaker.Models.Label>).Include("Groups").Distinct();

推荐答案

我讨厌发布的东西只是在几分钟之后搞清楚了。 在阅读了其他一些帖子后,我将查询更改为以下内容,以便对结果进行正确排序(但管理越来越难看!)

I hate it when I post something only to figure it out a few minutes later.  After reading some other posts, I changed the query to the following which properly orders the results (but its getting more and more ugly to manage!)


      var results = ((from label in Context.Labels
              from f in label.Label_Field
              where label.DeleteInd == false &&
              label.Facility.Name == Facility &&
              (label.LabelName.Contains(txtFind.Text) ||
              f.FieldText.Contains(txtFind.Text))
              select label) as ObjectQuery<MySite.LabelMaker.Models.Label>).Include("Groups").Distinct().OrderBy(c => c.LabelName);


这篇关于因为没有荣幸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆