为Entity Framework逆向工程一个表的子集 [英] Reverse engineering a subset of tables for Entity Framework

查看:123
本文介绍了为Entity Framework逆向工程一个表的子集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是EF,我拥有Entity Framework Power Tools扩展,它允许我基于给定数据库中的表来反向工程类。

I'm using EF, and I've got the Entity Framework Power Tools extension, which lets me reverse engineer classes based on tables in a given database.

我们有一个相当广泛的数据库,有很多表,我不需要代表。有没有任何简单的方法来选择这些的一个子集,并且只能反向工程?

We have a rather extensive DB, with a lot of tables that I do not need to represent. Is there any simple way to select a subset of these, and reverse engineer only those?

推荐答案

虽然它需要几个额外的步骤:

I found a solution which works, though it requires a couple of "extra" steps:

在项目中,右键单击并选择添加 > 新项目。从项目列表中选择数据 ADO.NET实体数据模型

In the project, right click and select Add --> new Item. Select Data on the left, and ADO.NET Entity Data Model from the items list.

从现在显示的对话框/向导中,您可以选择一个DB来生成模型,在这种情况下,您只能选择所需的表,视图和存储的过程和函数。

From the dialog / wizard that shows up now, you can select a DB to generate a model from, and in this case, you can select only the tables, views and stored Procedures and functions you need.

添加模型后,您可以在解决方案资源管理器中进行扩展,您应该在 YourModelName.edmx - > YourModelName.tt

After adding the model, you can expand it in the solution explorer, and you should find the classes you need under YourModelName.edmx --> YourModelName.tt

注意:你赢了'不能拖放源文件,但可以右键单击并选择 copy class 。然后,您可以将它们粘贴到需要的位置,并将它们的名称附加一个1。因此,您需要进行一些轻重构(更改文件名,类和名称空间),但仍然相当容易。

Note: You won't be able to drag and drop the source-files out, but you can right click and choose copy class. You can then paste them where you need them, and they will appear with a "1" appended to their names. You will therefore need to do some light refactoring (changing the name of the files, the classes, and the namespaces), but it is still fairly easy.

现在您可以删除原始模型(edmx-file)及其下的所有内容。

Now you can delete the original model (the edmx-file), and everything under it.

不是一个完美的解决方案,但是比起必须生成大量的表格表达(并等待VS完成工作!),如果你有很多不必要的表,视图等。

Not a perfect solution, but still easier than having to generate a huge number of table-representations (and wait for VS to complete the job!) if you've got a lot of unnecessary tables, views, etc.

这篇关于为Entity Framework逆向工程一个表的子集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆