EntityObject & Custom Attributes - A Thought

As slick as the EF is, there are limitations (one being my refusal to take 3 days to read MS's disjoint documentation).

A case in point:  An EntityObject classis defined as partial so one may add necessary properties, methods, attributes, etc. at will.  But the generated properties (database column accessors) do not allow for custom attributes.  They're not partial and C# doesn't allow for partial properties anyway.  

So how to add things like DisplayName or DefaultValue or something more esotaric like UnitType(Unit.Meter)?

Searching high and low renders nothing except some obscure references to System.ComponentModel.DataAnnotations.MetadataType(type).  So far I've found nothing definitive - the discussions seem related to the ASP end of things rather than the Forms.

Here, here and here.

It seems that the meta data can be extended via an associated class (MetadataType) but only if TypeDescriptor is used to fetch the metadata.  There may be no general solution to this issue but maybe an application specific solution can be created.

  • Create a custom reflection method that
    • Uses the MetadataType attribute
    • Combines the referenced attributes into the normal custom attributes (using standard reflection)

On the other hand, if I'm forcing the use of a special method to gather attributes, why not just use the TypeDescriptor approach?

More later....