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

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

问题描述

我看过订购Linq to Entities Query中有序项目中的子项目,这表明无法获取存储库以特定顺序返回实体图表中的子项目。

I've seen 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 ?

ie

 //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包装实体框架模型,并以精确的方式呈现数据,该视图由其设计。在ViewModel中执行排序,并将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天全站免登陆