I am looking to see if Extended Properties can be made to be part of Entities in EF 4.0, when the .edmx is generated or updated from the database. I also would like to see an example of running a stored procedure (function) from the .edmx in a T4 template, since I do have a procedure that returns the Extended Prop values.
Thanks
We can add extended properties to almost all SQL Server objects by right clicking on the object-> select properties-> select “Extended Properties” and add new properties to the object. So, after adding the new properties we might need to query those properties in the future. All done!
Sp_addextendedproperty stored procedure is used to create metadata about our database objects. Using this stored procedure we can put information about Sql server objects like name of developer who created the object, to track the version of objects inside database.
So, a few things to bear in mind here:
The general idea is that you can use your own tool to read the extended properties and change the EDMX XML.
You will be adding "Annotations" to the SSDL (store metadata in the EDMX) elements. These Annotation values will be based on your extended properties of the relative entities in the DB.
Later on, when T4 executes, T4 receives the metadata collections based on the EDMX elements. This metadata will contain the Annotations you previously wrote there. Just about any element can have one or more annotations. You can then add custom code to the T4 template to handle the annotations that are based on your extended properties. The designer will not show the annotations, and you can't manipulate them in the designer, but it should preserve them (won't overwrite them if they are present in the EDMX).
Of course, this would be a lot easier if the designer was extensible, or even if the designer-related code was usable by you. Right now, that's not the case. Most parts of EF are moving to open-source, but the designer is still not there (yet). If the designer ever gets into open source, then you can probably make changes to start using that - and given that the community keeps asking for this kind of feature, I imagine the community will change the source to make it happen anyway. Until then, you have to manually edit the EDMX or write some tool to do it for you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With