Reputation: 8016
I'm currently building an ASP.NET Dynamic Data project with LINQ to SQL for the data access. I know that adding the DisplayName
attribute to one of my properties will accomplish what I'm after, but I'd like to avoid doing this in the code that's generated by the LINQ to SQL designer.
Is there another easy way to do what I'm after or do I need to bite the bullet and just make my own metadata?
Upvotes: 0
Views: 1313
Reputation: 5944
You can use the MetadataTypeAttribute
for this as documented on MSDN.
From the documentation but for completeness (a little altered to seal the metadata inside the class):
If you have an entity Customer
with a Title
property, you would define the property again in the metadata class
using System;
using System.Web.DynamicData;
using System.ComponentModel.DataAnnotations;
[MetadataType(typeof(Customer.CustomerMetaData))]
public partial class Customer
{
class CustomerMetaData
{
// Apply RequiredAttribute
[Required(ErrorMessage = "Title is required.")]
public string Title;
}
}
Upvotes: 1