开发者

use Data Annotation to my Linq to SQL

开发者 https://www.devze.com 2023-02-02 06:12 出处:网络
i have a mvc web projec开发者_开发技巧t and i\'m using linq to sql i\'m using dataannotaion like this

i have a mvc web projec开发者_开发技巧t and i'm using linq to sql i'm using dataannotaion like this

public class ClientValidation
{
  [Required]
  public string name1st { get; set; }
 }

then in the linq class i add that above client class

[global::System.Data.Linq.Mapping.TableAttribute(Name = "dbo.Client")]
[MetadataType(typeof(ClientValidation))]
public partial class Client : INotifyPropertyChanging, INotifyPropertyChanged
{

}

every thing is going ok the question is when i re generate the linq when i add table or change any thing in database i need to rewrite [MetadataType(typeof(ClientValidation))] is there any other method to enable me regenerate the model and keep the data annotation as it


Write a partial class in another file with empty body and just annotate that with your attribute, partial classes and partial methods designed for this situations where you want to add a functionality to an autogenerated class or method.

0

精彩评论

暂无评论...
验证码 换一张
取 消