开发者

Add property decorator to partial class

开发者 https://www.devze.com 2023-01-11 22:17 出处:网络
I have a partial class in a dbml file. public partial class Comment string email Clearly I can\'t put a decorator on it bec开发者_如何学Goause this is a generated file and you shouldn\'t make chang

I have a partial class in a dbml file.

public partial class Comment
  string email

Clearly I can't put a decorator on it bec开发者_如何学Goause this is a generated file and you shouldn't make change in it yourself.

So I created another partial class;

public partial class Comment
  [IsEmailAddress]
  string email

The above doesn't work but I need something like that so I can validate the email address on the model.


You should used MetadataType like so...

[MetadataType(typeof(CommentMetadata))]
public partial class Comment {

}

public class CommentMetadata {
    [IsEmailAddress]
    public string email {get;set;}
}

That will allow you to add your attributes without it being overridden the next time you update your models.

0

精彩评论

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