How can I make the Entity data model designer use my database column descriptions?

徘徊边缘 提交于 2019-11-28 09:01:23

There is a feature request for this. Feel free to add your votes to help make this available in the future: Retrieve the SQL Descriptions in Entity-Framework feature request

Huagati has some great tools for working with EF and L2S. One of the features is updating the EF documentation based on the SQL database: Huagati website

From the website: Update ADO.NET Entity Data Model documentation from database retrieves free-text table and column descriptions, and index definitions from the database and updates the xml documentation fields in the EDMX designer with the descriptions.

It seems they look for these fields in the database and then update the model XML directly. Probably someone could create a VS Add-In that would do the same without the price if this is the only feature you wanted. I'll add this to my list of "future" projects (though I never seem to find time for these!).

Hope that helps!

I've been looking at ways of hacking something together to populate the edmx with the meta data from the database.

The summary and long description edmx properties are stored in elements under the EntityType element.

<EntityType Name="EntityName">
    <!-- Without this element classes are typically generated with 
         "No Metadata Documentation available." -->
    <Documentation>
            <Summary>Entity Summary</Summary>
            <LongDescription>Entity Long Description</LongDescription>
          </Documentation>
    <Key>
      <PropertyRef Name="Id" />
    </Key>
    <Property Name="Id" Type="String" Nullable="false" MaxLength="25" Unicode="false" FixedLength="true" />
    <!-- Lots of other properties -->
  </EntityType>

The relevant section of the edmx file, the Store Schema Definition Language (SSDL), is created by System.Data.Entity.Design.EntityStoreSchemaGenerator.GenerateStoreMetadata(). Or at least this is the case with EdmGen.

I'm going to see if the EntityStoreSchemaGenerator.StoreItemCollection can be modified before being used by EntityStoreSchemaGenerator.WriteStoreSchema(...) to output the XML.

Update

Well that was annoying. System.Data.Metadata.Edm.Documentation is sealed and only has an internal constructor. Both properties of interest can only be set internally as well. So it seems like a dead end approach.

I don't know that the designer itself has any extensibility points. However, once the Summary and LongDescription fields are populated in your edmx file, those value will remain there, even if you make other changes or re-updated your model from the database. Unless you delete a table and re-add it, those values will remain populated.

So you could either just copy and paste them all in one at a time (how many tables are in your model? This goes quicker than you think), or write a program to extract the info from your database (using SQL SMO or something), and have that program edit your edmx file, populating the Summary and LongDescription fields (make a backup of your edmx each time you try your program -- you don't want to botch your edmx file and have to start over).

If you have large models, and you're making lots of them, writing a program to do it automatically is worth your time. If you've only got a few models, with not too many tables, copy paste it is.

You might want to think about submitting feedback to the Entity Framework team here. Seems like the designer should automatically pick up on the description field from SQL Server. Would make a good feature request.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!