Take the 2-minute tour ×

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?

share|improve this question
add comment

1 Answer

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:


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:

share|improve this answer
add comment

Your Answer


