문제

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?

도움이 되었습니까?

해결책

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;
    }

}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top