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?
Hi Dynamic2008, I don't think that is possible with DD v1 you could do it with a custom filter in DD Preview 4, the only sort ability come from the DisplayColumn attribute like [DisplayColumn("DisplayColumnName","SortColumnName", false)] the final property
set the sort to decending if set to true. So for DD v1 you can only set a single column to be sorted on.
Dynamic Data
See my blog C# Bits | Twitter @sjnaughton Always seeking an elegant solution.
Why ASP.NET dynamic data simply doesn't generate application layers (e.g. Data Access, Business Logic and UI) so that they can be used seperately. What are the requirements for DD Preview 4? .NET 4.0?
If it needs .NET 4.0 I won't be able to use it.
Do you know of any other good data entry solution?
I think maybe best is to create an application myself which simply generates the layers for me, etc.
I have heard of TierDeveloper which is free; I may try that before developing an app myself.
Why ASP.NET dynamic data simply doesn't generate application layers (e.g. Data Access, Business Logic and UI) so that they can be used seperately. What are the requirements for DD Preview 4? .NET 4.0?
If it needs .NET 4.0 I won't be able to use it.
You need the 99.0.0.0 assemblies that come in the common files folder [:(] you could always use the bits from the old Futures project which had all the source code and use the filter repeater and just written custom filters see:
Dynamic Data Futures VS2008 SP1 RTM it this does not have the full source anylonger I have a copy [;)]
Dynamic Datafilters
See my blog C# Bits | Twitter @sjnaughton Always seeking an elegant solution.
A potential solution: just an idea cam to me when I was asleep that if second parameter (SortColumn) of DisplayColumn attribute needs an existing property to be able to sort the results what I might be able to do is to add a new property to my class such
as "ReportRoleDisplay" and put the logic I wrote for ToString() inside its get{} statement. Then I will set the SortColumn to be the name of the new property. It may work!
I will try that on Tuesday; now enjoying my last summer bank holiday ;)
Good Idea I did something like this in a recent project we created a calculated column that just concatenated the two columns we wanted to sort on and used them as the display column. [:D]
Dynamic DataCalculated ColumnSort Column
See my blog C# Bits | Twitter @sjnaughton Always seeking an elegant solution.
I might be able to do is to add a new property to my class such as "ReportRoleDisplay" and put the logic I wrote for ToString() inside its get{} statement. Then I will set the SortColumn to be the name of the new property. It may work!
It wont work as the property does not exist in the DB [:(]
Dynamic DataSort Filters
See my blog C# Bits | Twitter @sjnaughton Always seeking an elegant solution.
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
Shakti Singh...
Star
10870 Points
1827 Posts
Re: How to Sort my objects in Dynamic Data?
Aug 28, 2009 05:25 PM|LINK
try using orderby as
using (var context = new MIPortalEntities())
Shakti Singh Tanwar
.Net Trainer (MCP,MCAD.net,MCSD.net,MCTS,MCPD.net[web])
sjnaughton
All-Star
27330 Points
5459 Posts
MVP
Re: How to Sort my objects in Dynamic Data?
Aug 29, 2009 11:48 AM|LINK
Hi Dynamic2008, I don't think that is possible with DD v1 you could do it with a custom filter in DD Preview 4, the only sort ability come from the DisplayColumn attribute like [DisplayColumn("DisplayColumnName","SortColumnName", false)] the final property set the sort to decending if set to true. So for DD v1 you can only set a single column to be sorted on.
Dynamic Data
Always seeking an elegant solution.
Dynamic2008
Member
127 Points
164 Posts
Re: How to Sort my objects in Dynamic Data?
Aug 29, 2009 05:01 PM|LINK
Ah, that's bad to hear.
Why ASP.NET dynamic data simply doesn't generate application layers (e.g. Data Access, Business Logic and UI) so that they can be used seperately. What are the requirements for DD Preview 4? .NET 4.0?
If it needs .NET 4.0 I won't be able to use it.
Do you know of any other good data entry solution?
I think maybe best is to create an application myself which simply generates the layers for me, etc.
I have heard of TierDeveloper which is free; I may try that before developing an app myself.
Shakti Singh...
Star
10870 Points
1827 Posts
Re: How to Sort my objects in Dynamic Data?
Aug 29, 2009 05:59 PM|LINK
Have you tried my solution?
Shakti Singh Tanwar
.Net Trainer (MCP,MCAD.net,MCSD.net,MCTS,MCPD.net[web])
Dynamic2008
Member
127 Points
164 Posts
Re: How to Sort my objects in Dynamic Data?
Aug 29, 2009 07:14 PM|LINK
Shakti,
I believe that's not a solution.
That linq statement returns only one row anyway, so there i no point in ordering that.
Instead of First() maybe I should have written Single() to be more clear.
Thanks,
sjnaughton
All-Star
27330 Points
5459 Posts
MVP
Re: How to Sort my objects in Dynamic Data?
Aug 29, 2009 11:13 PM|LINK
You need the 99.0.0.0 assemblies that come in the common files folder [:(] you could always use the bits from the old Futures project which had all the source code and use the filter repeater and just written custom filters see: Dynamic Data Futures VS2008 SP1 RTM it this does not have the full source anylonger I have a copy [;)]
Dynamic Data filters
Always seeking an elegant solution.
Dynamic2008
Member
127 Points
164 Posts
Re: How to Sort my objects in Dynamic Data?
Aug 30, 2009 06:25 AM|LINK
Thanks I will look into that.
A potential solution: just an idea cam to me when I was asleep that if second parameter (SortColumn) of DisplayColumn attribute needs an existing property to be able to sort the results what I might be able to do is to add a new property to my class such as "ReportRoleDisplay" and put the logic I wrote for ToString() inside its get{} statement. Then I will set the SortColumn to be the name of the new property. It may work!
I will try that on Tuesday; now enjoying my last summer bank holiday ;)
sjnaughton
All-Star
27330 Points
5459 Posts
MVP
Re: How to Sort my objects in Dynamic Data?
Aug 30, 2009 10:55 AM|LINK
Good Idea I did something like this in a recent project we created a calculated column that just concatenated the two columns we wanted to sort on and used them as the display column. [:D]
Dynamic Data Calculated Column Sort Column
Always seeking an elegant solution.
sjnaughton
All-Star
27330 Points
5459 Posts
MVP
Re: How to Sort my objects in Dynamic Data?
Aug 31, 2009 09:37 AM|LINK
It wont work as the property does not exist in the DB [:(]
Dynamic Data Sort Filters
Always seeking an elegant solution.