I would like to call the method in ObjectContext, which returns EntityCollection, and sort it by default. For example, imagine that I have the following class table Category:
- CategoryID (PK)
- Name
- Foreign key ParentID (FK_Category) pointing to the CategoryID itself.
(This table is the basis for the tree structure of categories and subcategories)
Now in my data model public partial class Category : EntityObjectit has a property that returns all categories that have ParentID == CategoryID, in other words EntityCollection<Category> SubCategories.
Ok, now I want to show all categories and subcategories on my page using a repeater:
<asp:Repeater ID="rptSubCategories" runat="server">
<ItemTemplate>
<%# Eval("CategoryID") %> - <%# Eval("Name") %>
<asp:Repeater ID="rptSubCategoryCategories" runat="server" DataSource='<%#Eval("SubCategories")) %>'>
<ItemTemplate>
<%# Eval("CategoryID") %> - <%# Eval("Name") %>
</ItemTemplate>
</asp:Repeater>
</ItemTemplate>
</asp:Repeater>
Then in the code behind I set the DataSource:
IList<Category> categoryList = new CategoryProvider().GetAll();
rptSubCategories.DataSource = categoryList;
rptSubCategories.DataBind();
! , rptSubCategoryCategories . , , - DataSource:
DataSource='<%# Eval("SubCategories")) %>'
DataSource='<%# ((EntityCollection<Category>)Eval("SubCategories")).OrderBy(p => p.Name) %>'
- , , OrderBy. - , DynamicData, http://www.asp.net/learn/3.5-SP1/video-291.aspx
DisplayColumnAttribute. - , .
.NET 4.0 BETA 2
, !