I am using Entity Framework with ASP.NET Dynamic Data 3.5. I have a ReportRole class which has been extended as following:
[DisplayColumn("ReportRoleId")]
[MetadataType(typeof(ReportRole_MD))]
[DisplayName("Report Role")]
public partial class ReportRole
{
public override string ToString()
{
var result = String.Empty;
using (var context = new MIPortalEntities())
{
result = (from rr in context.ReportRole
where rr.ReportRoleId == this.ReportRoleId
let textToDisplay = rr.Report.ReportName + "--" + rr.Role.RoleName
select textToDisplay).First();
}
return result;
}
}
public class ReportRole_MD
{
[UIHint("ReadOnlyText")]
public object ReportRoleId { get; set; }
[UIHint("ReadOnlyText")]
public object UpdatedDate { get; set; }
public object Report { get; set; }
public object Role { get; set; }
}
The display text for each report role would be like "ReportName -- RoleName".
By default the ReportRoles are sorted by ReportRoleId, so how can I say the ReportRoles should be sorted based on the value which is returned from ToString() method?
Dynamic2008
Member
127 Points
164 Posts
How to Sort my objects in Dynamic Data?
Aug 28, 2009 03:23 PM|LINK
I am using Entity Framework with ASP.NET Dynamic Data 3.5. I have a ReportRole class which has been extended as following:
[DisplayColumn("ReportRoleId")] [MetadataType(typeof(ReportRole_MD))] [DisplayName("Report Role")] public partial class ReportRole { public override string ToString() { var result = String.Empty; using (var context = new MIPortalEntities()) { result = (from rr in context.ReportRole where rr.ReportRoleId == this.ReportRoleId let textToDisplay = rr.Report.ReportName + "--" + rr.Role.RoleName select textToDisplay).First(); } return result; } } public class ReportRole_MD { [UIHint("ReadOnlyText")] public object ReportRoleId { get; set; } [UIHint("ReadOnlyText")] public object UpdatedDate { get; set; } public object Report { get; set; } public object Role { get; set; } }The display text for each report role would be like "ReportName -- RoleName".
By default the ReportRoles are sorted by ReportRoleId, so how can I say the ReportRoles should be sorted based on the value which is returned from ToString() method?
Thanks,
ASP.NET Dynamic Data Entity Framework Sort Column