Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

extract SQL Server Extended properties as part of EF 4.0 Entites or run stored procedure in T4 template that does

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

like image 858
user643258 Avatar asked Mar 03 '11 17:03

user643258


People also ask

How do I get extended properties in SQL Server?

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!

What is sp_ addextendedproperty in SQL Server?

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.


1 Answers

So, a few things to bear in mind here:

  • The designer is not really extensible, but the provider is. That doesn't really help much because writing an EF provider is not a walk in the park. It's really complex.
  • The designer-related code, including the bits that relate to metadata, is mostly sealed and internal and almost completely unusable by you.
  • However, the EDMX file (the XML file itself) is very well documented: http://msdn.microsoft.com/en-us/data/jj650889 ... You can freely modify the XML yourself (by hand or through some Add-in or external utility), as long as you stick to the specifications.

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.

like image 187
DevPrime Avatar answered Oct 17 '22 06:10

DevPrime