如何使实体数据模型设计器使用我的数据库列描述?

发布于 2024-08-31 14:27:11 字数 234 浏览 10 评论 0原文

我正在将 EF4 与 Visual Studio 2010 结合使用。我已经创建了一个 SQL 数据库,并且我的所有列都使用 SQL 管理工作室中的“描述”属性进行了记录。当我在 Visual Studio 中创建 edmx 时,如何让它读取这些描述并使用它们向生成的类添加注释?我知道我可以在 edmx 属性中使用 Summary 和 LongDescription,但我正在寻找一种方法来执行此操作,而无需复制和粘贴每个描述。

谢谢!

I am using EF4 with Visual Studio 2010. I have a SQL database already created and all my columns are documented with the Description property in SQL management studio. When I create the edmx in Visual Studio, how can I make it read those descriptions and use them to add comments to my generated classes? I know I can use the Summary and LongDescription in the edmx properties but I'm looking for a way to do this without having to copy and paste every description.

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

坠似风落 2024-09-07 14:27:11

有一个针对此的功能请求。请随意添加您的投票,以帮助将来实现此功能:
检索实体中的 SQL 描述-框架功能请求

Huagati 有一些很棒的工具可用于使用 EF 和 L2S。其中一项功能是根据 SQL 数据库更新 EF 文档:
华加体网站

来自网站:从数据库更新 ADO.NET 实体数据模型文档从数据库检索自由文本表和列描述以及索引定义,并使用描述更新 EDMX 设计器中的 xml 文档字段。

看起来他们在数据库中查找这些字段,然后直接更新模型 XML。如果这是您唯一想要的功能,也许有人可以创建一个 VS 插件,它可以在没有价格的情况下执行相同的操作。我会将其添加到我的“未来”项目列表中(尽管我似乎从来没有时间做这些!)。

希望有帮助!

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!

乖乖兔^ω^ 2024-09-07 14:27:11

我一直在寻找将一些东西组合在一起以使用数据库中的元数据填充 edmx 的方法。

摘要和详细描述 edmx 属性存储在 EntityType 元素下的元素中。

<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>

edmx 文件的相关部分,即存储架构定义语言 (SSDL),由 System.Data.Entity.Design.EntityStoreSchemaGenerator.GenerateStoreMetadata()。或者至少 EdmGen 的情况是这样。

我要看看 EntityStoreSchemaGenerator 是否.StoreItemCollection 可以在被 EntityStoreSchemaGenerator.WriteStoreSchema(...) 用于输出 XML 之前进行修改。

更新

嗯,这很烦人。 System.Data.Metadata.Edm.Documentation 是密封的并且只有一个内部构造函数。这两个感兴趣的属性也只能在内部设置。
所以这似乎是一个死胡同。

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.

零度° 2024-09-07 14:27:11

不知道设计者本身有什么扩展点。但是,一旦在 edmx 文件中填充 Summary 和 LongDescription 字段,这些值将保留在那里,即使您进行其他更改或从数据库重新更新模型也是如此。除非您删除表并重新添加它,否则这些值将保持填充状态。

因此,您可以一次将它们全部复制并粘贴到一个中(您的模型中有多少个表?这比您想象的要快),或者编写一个程序从数据库中提取信息(使用 SQL SMO 或其他东西) ,并让该程序编辑您的 edmx 文件,填充“Summary”和“LongDescription”字段(每次尝试您的程序时都对您的 edmx 进行备份 - 您不想弄乱您的 edmx 文件并必须重新开始)。

如果您有大型模型,并且要制作很多模型,那么编写一个程序来自动完成它是值得您花时间的。如果您只有几个模型,并且没有太多表格,则可以复制粘贴。

您可能需要考虑在此处。看起来设计者应该自动从 SQL Server 中获取描述字段。会提出一个很好的功能请求。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文