You are better overriding the ToString method like this:
[MetadataType(typeof(FlyerMetadata))]
public partial class Flyer
{
public override string ToString()
{
return this.CreatedDate = DateTime.Now.ToString("MMM-dd-yyyy");
}
}
if you want a field in the DB set to the dateTime it was created then you could do this by overriding the table Insert method (I am assuming you are using Linq to SQL and not Entity Framework) like this:
public partial class NorthwindDataContext
{
partial void InsertCustomer(Customer instance)
{
instance.CreationDate = DateTime.Now;
this.ExecuteDynamicInsert(instance);
}
}
And then you could just display the CreationDate filed in you DDL the other advantage is that custom fields will not sort on because the sort is done in the DB so if you have a DB field like above then you can sort on it and get the effect you want.
Dynamic Data
See my blog C# Bits | Twitter @sjnaughton Always seeking an elegant solution.
All-Star
17916 Points
5681 Posts
MVP
Re: DisplayFormatAttribute doesn't work when this is a ForeignKey DropDownList / Hyperlink
Jan 08, 2010 03:22 AM|sjnaughton|LINK
You are better overriding the ToString method like this:
if you want a field in the DB set to the dateTime it was created then you could do this by overriding the table Insert method (I am assuming you are using Linq to SQL and not Entity Framework) like this:
And then you could just display the CreationDate filed in you DDL the other advantage is that custom fields will not sort on because the sort is done in the DB so if you have a DB field like above then you can sort on it and get the effect you want.
Dynamic Data
Always seeking an elegant solution.