开发者

partial classes + DataAnnotations

I've got a class that was generated for me by the Entity Framework:

Models/EF.tt/Product.cs

public partial class X
{
  public int Name { get; set; }
  ...
}

I don't want to modify it because it's managed by the EF editor and it will wipe out my modifications any time I regenerate it, so I'm putting code into a separate file. Because the classes are declared as partial I can do useful things... what I haven't been able to figure out is how to use DataAnnotations for the properties.

Models/EF.custom开发者_如何学运维.cs

public partial class X
{
  [Display(Name = "My Name")]
  public int Name { get; set; }
  ...
}

which fails... what is the proper way to do this?


Your going to want to use a metadatatype:

http://ryanhayes.net/blog/data-annotations-for-entity-framework-4-entities-as-an-mvc-model/

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜