问题
In the accepted answer to this SO question there is an explanation about structural annotations, a way to customize the data on the EDMX files generated by the Entity Framework designer. This feature is used by the Portable Extensible Metadata framework in order to add validation information to the entities defined in an EF model, by adding extra entries to the "Properties" window of the created entities and its properties.
My question is: what should I do if I want to create my own custom structural annotations engine? That is, I want Visual Studio to show some extra entries in the properties window for the EF entities; and I want to integrate my own code with the EDMX code generator in order to generate structural annotations. I guess that I need to create a Visual Studio extension but apart from this, I could not find any further information anywhere else. Where should I look for information on this subject?
回答1:
Entity framework has very low extensibility on ORM layer but it has surprisingly good extensibility on designer layer. The core of extensibility is based on few interfaces which can be implemented to add custom features to EDMX designer as VS extension.
The step by step process of adding custom property to designer is described in Entity Framework 4 in Action book. You can also use Designer Extension Starter Kit to get some prepared templates and kick start for creating your own extensions.
These features targets EFv4. Extension starter kit doesn't work with June 2011 CTP and its new designer.
来源:https://stackoverflow.com/questions/7582898/how-to-integrate-my-own-structural-annotations-engine-in-the-entity-framework-de