订购在LINQ到实体查询订购物品中的子项 [英] Ordering sub-items within ordered items in a Linq to Entities Query

查看:81
本文介绍了订购在LINQ到实体查询订购物品中的子项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几桌,人数,ListingImages和相关房源几个人。 ListingImages是有关资讯,让你可以为每个清单许多ListingImages。

I have a few tables, Listings, ListingImages and a few others related to Listings. ListingImages is related to Listings so that you can have many ListingImages per Listing.

当我查询这个表我做的;

When I query this table I do;

IQueryable<Listing> ListingToSendToView = (from x in DBEntities.ListingSet.Include("ListingImages")
                                                                          .Include("OtherTables")
                                           where x.Listing.ID == (int)LID
                                           orderby x.ID descending
                                           select x).First();

现在,这是好的。不过,我现在想的ListingImages各自独立上市内(由ImageOrder列我在那个表)进行排序。

Now this is fine. However, I now want to sort the ListingImages independently within each Listing (by an ImageOrder column I have in that table).

我怎样才能做到这一点,并通过所有我包括(......)。难道是不好的形式为这个解决方案似乎工作的ListingImages的视图中进行排序?

How can I do this and pass all my Includes(...). Would it be bad form to sort the ListingImages within the View as this solution seems to work?

干杯

推荐答案

我想你将不得不将其在视图中进行排序,因为如果你希望每个组有不同的排序,你必须这样做手工。唯一的其他选择是从控制器复制到字典或列表结构和排序,它的顺序进行复制,然后返回...虽然我甚至不知道从哪里开始的那一个。

I think you are going to have to sort it in the view, because if you want each group to have a different sorting, you have to do that manually. The only other option is to copy it to a dictionary or list structure and sort and copy it in the order, then return that from the controller... though I don't even know where to begin on that one.

我不认为排序的看法是坏的形式,因为它的UI逻辑的一部分(或用户界面的需求反正)...这将是不好的形式向视图中查询数据,并注意不要把太多的逻辑(我不知道你说的是复杂性),但只要其唯一的排序,我认为这是确定。

I don't think sorting on the view is bad form, because it's part of the UI logic (or the UI's needs anyway)... it would be bad form to query data within the view, and be careful not to put too much logic in (I don't know the complexity you are talking about), but as long as its only sorting, I think that's OK.

心连心。

这篇关于订购在LINQ到实体查询订购物品中的子项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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