【发布时间】:2011-04-05 05:43:30
【问题描述】:
我见过Ordering sub-items within ordered items in a Linq to Entities Query,这表明无法让存储库以特定顺序返回实体图中的子项。
如果这是对的,有什么想法可以在 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 对象?
【问题讨论】:
标签: c# asp.net-mvc entity-framework asp.net-mvc-2 entity-framework-4