locked
Multiple Columns for DisplayColumn? RRS feed

  • Question

  • User1014298547 posted

    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?

    Monday, December 17, 2012 12:00 PM

All replies

  • User-330204900 posted

    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

    Friday, December 21, 2012 7:07 AM
  • User1014298547 posted

    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?

     

     

    Tuesday, January 8, 2013 2:53 PM
  • User1014298547 posted

    -

    Tuesday, January 8, 2013 3:04 PM
  • User-330204900 posted

    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.

    Tuesday, January 8, 2013 3:57 PM