0

I've spent two days scouring the internet for what I'm doing wrong. Every tutorial and question/answer here shows the same solution :

[MetadataType(typeof(PEOPLE_Metadata))]
public partial class PEOPLE { }

public class PEOPLE_Metadata
{
    [DisplayName("Social Security Number")]
    public string SSN { get; set; }
}

The problem is that this isn't working for me. When I crawl through the properties for the PEOPLE class in my view, the SSN property shows no attributes nor customattributes. I can see that the PEOPLE class has the MetadataType attribute. I've tried separating the classes into separate files, the same file, the metadata class inside the partial, the two separate, setting the metadata class to partial, internal, sealed, public, everything. I have literally no idea why this isn't working for me, when by all accounts it ought to.

Please help me.

The PEOPLE class is as below :

public partial class PEOPLE
{
    public int ID { get; set; }
    public string SSN { get; set; }
    public string NAME { get; set; }
}

It may be worth emphasizing that I'm trying to see the metadata attributes of the properties through reflection. More research showed me how to pull out the metadata attribute and then reflect into the metadata class, PEOPLE_Metadata, but I'd really prefer minimizing the amount of reflection crawling being done.

Sparrow
  • 2,548
  • 1
  • 24
  • 28
Pfhoenix
  • 23
  • 6

1 Answers1

0

This question was asked many years ago but I recently ran into the same problem using a WPF application using .net and a "Database First" solution. The EDMX .tt file would not update from the MetadataType decorator.

I am not sure what type of project the OP was using, but in my case I found that I had to create a validation context on my own and validate manually for what I needed.

Validation does not work when I use Validator.TryValidateObject - This post led me to the solution that the MetadataType decorator is not being recognized by my project.

I followed the example and create a generic class that accepts the model and meta data and I could remove the partials and basically just have a "Meta Data" model.

Hopefully this addition helps point you in the right direction if you are not using an MVC application.

kirikintha
  • 468
  • 5
  • 11