This is a migrated thread and some comments may be shown as answers.

Sorting additional properites on EntityDataSource

1 Answer 76 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Bjorn
Top achievements
Rank 1
Bjorn asked on 04 Sep 2010, 02:48 PM

I have the following mapped in my Entity Data Model to my Database
Products
ProductName
CreatedDate
UpdatedDate
...

I then created a partial class, which gives an additional property to Products
public partial class Product
{
    public DateTime LatestDate
    {
       get
       {
            if(UpdateDate.HasValue)  return UpdateDate.Value;
             return CreatedDate;
        }
    }
}

I then did the following:

 

 

 

 

<asp:EntityDataSource ID="EntityDataSource1" runat="server"

 

 

 

 

ConnectionString="name=TwModelContainer"

 

 

 

 

 

 

 

 

 

DefaultContainerName="TwModelContainer" EnableFlattening="false"

 

 

 

 

EntitySetName="Products">

 

 

 

 

 

 

 

 

 

</asp:EntityDataSource>

 

 


<telerik

 

 

:RadGrid ID="RadGrid1" runat="server" AllowPaging="True"

 

 

 

 

AutoGenerateColumns="False" DataSourceID="EntityDataSource1"

 

 

 

 

GridLines="None" onitemcreated="RadGrid1_ItemCreated" AllowSorting="True">

 

<

 

 

 

MasterTableView DataSourceID="EntityDataSource1" DataKeyNames="Id">

 

<

 

 

telerik:GridSortExpression FieldName="LastDate" SortOrder="Descending" />


Unfortunately, this does not work. I can easily show the created field LastDate in the Grid, but sorting won't work. It gives me the following error:
 'LastDate' is not a member of type 'TwModel.Product' in the currently loaded schemas. Near simple identifier, line 6, column 4

I guess in means that sorting works only for what is availabe in the database schema, but how would I accomplish the above with an additional calculated property, i.e. LastDate?

 

 

 

1 Answer, 1 is accepted

Sort by
0
Iana Tsolova
Telerik team
answered on 08 Sep 2010, 03:29 PM
Hello Bjorn,

As the EntityDataSource supports sorting out-of-the-box. Thus when RadGrid is bound to EntityDataSource and sort it, the sorting is done by the EntityDataSource control directly but through the grid mechanisms.
You can try binding the grid to ObjectDataSource for instance which will use your custom Product class.

Sincerely yours,
Iana
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Grid
Asked by
Bjorn
Top achievements
Rank 1
Answers by
Iana Tsolova
Telerik team
Share this question
or