I tired your suggestion above. However, I get a "The display column 'StartDateSort' specified for the table 'Visits' does not exist." at run time. Below is my data annotation code. I kept it simple for testing. I will go back and add more fields once
I get it working:
namespace Admiral_CGDoorsModel
{
[MetadataType(typeof(VisitMetaData))]
[ScaffoldTable(true)]
[DisplayColumn("StartDateSort")]
[DisplayName("Visits")]
public partial class Visit
{
public string StartDateSort
{
get{return StartDate; }
}
public Visit()
{
RecordID = Guid.NewGuid();
}
public partial class VisitMetaData
{
[ScaffoldColumn(false)]
[Display(Name = "RecordID",Order = 10)]
public Object RecordID { get; set; }
[ScaffoldColumn(false)]
[Display(Name = "ShipID",Order = 20)]
public Object ShipID { get; set; }
[ScaffoldColumn(true)]
[Display(Name = "End Date",Order = 30)]
public Object EndDate { get; set; }
[ScaffoldColumn(true)]
[Display(Name = "Start Date",Order = 40)]
public Object StartDate { get; set; }
}
}
}
Hi SonnyTate, EF does not support custom properties and as such DD does not see them if this is a serious requirement use Computed Column in the DB or Switch to Linq to SQL
See my blog C# Bits | Twitter @sjnaughton Always seeking an elegant solution.
I guess I could have asked my question better. All I am trying to is to have a dropdown filter display a list of ships and start dates from my Visits table. This table has ShipName and StartDate fields. I would like dropdown to display ShipName ASC and StartDate
DESC, like this:
HMS Britannic, 1942-08-03
HMS Britannic, 1932-02-23
HMS Queen Elizabeth, 1967-07-14
HMS Queen Elizabeth, 1965-02-18
HMS Titanic, 1913-11-03
HMS Titanic, 1911-05-22
This is the code I have so far:
namespace Admiral_NSSAModel
{
[MetadataType(typeof(VisitMetaData))]
[ScaffoldTable(true)]
[DisplayColumn("ShipName", "ShipName")]
[DisplayName("Visits")]
public partial class Visit
{
public override string ToString()
{
return ShipName.ToString() + " " + string.Format("{0:yyyy-MM-dd}", StartDate);
}
public Visit()
{
VisitID = Guid.NewGuid();
}
public partial class VisitMetaData
{
[ScaffoldColumn(true)]
public Object ShipName { get; set; }
[ScaffoldColumn(true)]
[DataType(DataType.Date)]
public Object StartDate { get; set; }
}
}
}
While this works, it only sorts by ship. Is there any way I can do it by ShipName ASC StartDate DESC?
SonnyTate
Member
24 Points
22 Posts
Multiple Columns for DisplayColumn?
Dec 17, 2012 04:00 PM|LINK
Split off from http://forums.asp.net/t/1246767.aspx/1?Multiple+Columns+for+DisplayColumn+. Please don't necropost.
I tired your suggestion above. However, I get a "The display column 'StartDateSort' specified for the table 'Visits' does not exist." at run time. Below is my data annotation code. I kept it simple for testing. I will go back and add more fields once I get it working:
namespace Admiral_CGDoorsModel { [MetadataType(typeof(VisitMetaData))] [ScaffoldTable(true)] [DisplayColumn("StartDateSort")] [DisplayName("Visits")] public partial class Visit { public string StartDateSort { get{return StartDate; } } public Visit() { RecordID = Guid.NewGuid(); } public partial class VisitMetaData { [ScaffoldColumn(false)] [Display(Name = "RecordID",Order = 10)] public Object RecordID { get; set; } [ScaffoldColumn(false)] [Display(Name = "ShipID",Order = 20)] public Object ShipID { get; set; } [ScaffoldColumn(true)] [Display(Name = "End Date",Order = 30)] public Object EndDate { get; set; } [ScaffoldColumn(true)] [Display(Name = "Start Date",Order = 40)] public Object StartDate { get; set; } } } }What am I doing wrong?
sjnaughton
All-Star
27391 Points
5485 Posts
MVP
Re: Multiple Columns for DisplayColumn?
Dec 21, 2012 11:07 AM|LINK
Hi SonnyTate, EF does not support custom properties and as such DD does not see them if this is a serious requirement use Computed Column in the DB or Switch to Linq to SQL
Always seeking an elegant solution.
SonnyTate
Member
24 Points
22 Posts
Re: Multiple Columns for DisplayColumn?
Jan 08, 2013 06:53 PM|LINK
I guess I could have asked my question better. All I am trying to is to have a dropdown filter display a list of ships and start dates from my Visits table. This table has ShipName and StartDate fields. I would like dropdown to display ShipName ASC and StartDate DESC, like this:
This is the code I have so far:
namespace Admiral_NSSAModel { [MetadataType(typeof(VisitMetaData))] [ScaffoldTable(true)] [DisplayColumn("ShipName", "ShipName")] [DisplayName("Visits")] public partial class Visit { public override string ToString() { return ShipName.ToString() + " " + string.Format("{0:yyyy-MM-dd}", StartDate); } public Visit() { VisitID = Guid.NewGuid(); } public partial class VisitMetaData { [ScaffoldColumn(true)] public Object ShipName { get; set; } [ScaffoldColumn(true)] [DataType(DataType.Date)] public Object StartDate { get; set; } } } }While this works, it only sorts by ship. Is there any way I can do it by ShipName ASC StartDate DESC?
SonnyTate
Member
24 Points
22 Posts
Re: Multiple Columns for DisplayColumn?
Jan 08, 2013 07:04 PM|LINK
-
sjnaughton
All-Star
27391 Points
5485 Posts
MVP
Re: Multiple Columns for DisplayColumn?
Jan 08, 2013 07:57 PM|LINK
Hi Sony, I the only way I can think of doing this would be to create you own custom field template based on the ForeignKey field template.
Always seeking an elegant solution.