ekkis
ekkis

Reputation: 10226

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?

Upvotes: 9

Views: 8368

Answers (1)

Kevin LaBranche
Kevin LaBranche

Reputation: 21088

Your going to want to use a metadatatype:

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

Upvotes: 13

Related Questions