订购实体框架分项EditorFor [英] Ordering Entity Framework sub-items for EditorFor

查看:79
本文介绍了订购实体框架分项EditorFor的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我见过的<一个href=\"http://stackoverflow.com/questions/3565249/ordering-sub-items-within-ordered-items-in-a-linq-to-entities-query\">http://stackoverflow.com/questions/3565249/ordering-sub-items-within-ordered-items-in-a-linq-to-entities-query这表明没有获取库中的实体图形以特定顺序返回分项的方式。

I've seen http://stackoverflow.com/questions/3565249/ordering-sub-items-within-ordered-items-in-a-linq-to-entities-query which suggests that there is no way of getting the repository to return sub-items in an entity graph in a specific order.

如果这是正确的,关于如何在EditorFor订购项目的任何想法?

If that's right, any thoughts on how to order the items in an EditorFor ?

 //This works but returns a random order
 <%: Html.EditorFor(model => model.HPERDET.HORDERS) %>


 //This errors with "Templates can be used only with field access, property access, single-dimension array index, or single-parameter custom indexer expressions."
 <%: Html.EditorFor(model => model.HPERDET.HORDERS.OrderBy(m=>m.APP_DATE)) %>

 //presorting the HORDERS into 
 //a public IOrderedEnumerable<HORDER> SortedHorders { get; set; } 
 //and ordering in my view model works, but breaks the binding because 
 //the generated html inputs no longer have the correct hierarchical names
 <%: Html.EditorFor(model => model.SortedHorders) %>

那么,有没有一种方法,以便与EditorFor使用它们,而不诉诸组装POCO对象复制EF的人,但在所有顺序图子实体排序?

So is there a way to sort the sub-entities in graph in order to use them with EditorFor without resorting to assembling POCO objects duplicating the EF ones in all but order ?

推荐答案

这是一个ViewModel的优秀案例。包装的ViewModels实体框架模型和present在$ P $的数据pcisely由其设计视图所需要的方式。在视图模型进行排序和EditFor绑定到自定义排序属性。

This is an excellent case for a ViewModel. ViewModels wrap the Entity Framework model and present the data in precisely the way required by the View for which it is designed. Perform the sorting in the ViewModel and bind the EditFor to the custom-sorted property.

这篇关于订购实体框架分项EditorFor的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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