2

I'm trying to read buddy class metadata information for usage outside of the normal asp.net mvc 2 validation process. I thought it would be as simple as saying:

DataAnnotationsModelMetadataProvider metadataProvider = new DataAnnotationsModelMetadataProvider();

var metaData = metadataProvider.GetMetadataForType(() => new T(), typeof (T));

That works, but is returning me the entire types metadata information and not just what is in the buddy information. According to the MVC2 source ( It uses the buddy class support from DataAnnotations, ) it should support getting the buddy data information but I don't see the part in the code where it reflects into the Metadatatype() attribute.

Generally confused here. Did I miss an overload or something?

John Farrell
  • 24,673
  • 10
  • 77
  • 110

1 Answers1

0

I had the same problem. I have looked at literally 30 maybe 40 tutorials about why this Entity Framework "Database First" partial classes wasn't working. Then I found this post -- MVC 4 EF5 Database First set Default Values in Partial Class -- that gave the following suggestion:

[MetadataType(typeof(CompanyMD))]

belongs in the partial class generated by the EF, even though it will be erased if and when you change the model. So your EF-generated file should look like this:

Community
  • 1
  • 1
jmorrissette
  • 133
  • 1
  • 10