如何使用 EntityModelSchemaGenerator 生成少于整个模型的模型?
我们有一个庞大的(并且还在不断增长!)的数据库。我们试图不必手动构建模型,我们发现了这一点 EdmGen2< /a> 它应该为我们构建我们的 EDMX 实体模型。
由于我们有这么大的数据库,我们不希望所有的表都在同一个模型中。我们让一切正常工作,但生成的模型包含我们所有的表。
EntityStoreSchemaGenerator 中有一个只读的表列表。这是(事实上)我们所有的桌子。
该工具制作的模型是否会小于我们的完整数据库?我们可以选择要放置的表并只使用它们吗?
We have a big (and growing!) database. We're trying to not have to build the models by hand, and we found this
EdmGen2 which is supposed to build our EDMX entity models for us.
Since we have such a big database we'd like to not have all of our tables in the same Model. We got it all to work, but the generated model has all of our tables.
There is a read only list of the tables inside of the EntityStoreSchemaGenerator. It is (in fact) all of our tables.
Will this tool make a model that is less then our full database? Can we select which tables we want to put it and only use those?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
EdmGen2 代码附带一个名为 /RetrofitModel 的选项。这种模式的关键点是运行一些数据挖掘算法来查看数据库实例中是否存在任何明显的类似继承的关系,如果有,则生成包含这些继承的 EDMX。
但是,/RetrofitModel 选项的另一个功能是它允许选择表。例如,如果有 AdventureWorks 示例数据库,您可以发出以下语句:
它将显示数据库中的表列表,此时您可以检查您想要在模型中包含哪些表。
The EdmGen2 code comes with an option called /RetrofitModel. The key point of this mode is that is runs some data mining algorithms to see if there are any obvious inheritance-like relationships in the database instance, and if so, generates an EDMX that includes those inheritances.
However, another feature of the /RetrofitModel option is that it allows one to select tables. For instance, if one has the AdventureWorks sample database, you can issue this statement:
It will bring up a list of the tables in the database, at which point you can check which ones you want to have in your model.
tupleFraction 参数有助于定义“重要”子类的含义。数据挖掘规则是启发式的,因此它们可能会发现常识可能不同意的模式。
tupleFraction 参数说明了这一点(对于某些规则):如果 EdmGen++ 认为它已经找到了一个子类,但新子类的实例数量少于其父类的 tupleFraction,则认为新子类“无关紧要”并且不这样做创建它。该参数是可选的 - 如果您不指定它,我认为它会设置为 0.05 (5%)。
当前版本仅允许通过 UI 指定表。然而,从文件或其他来源提取表列表是一个简单的添加 - 我会将其添加到下一版本的待办事项列表的顶部。
更新:我们更新了 code.msdn.microsoft.com/edmgen2 上的代码,以允许在不使用 GUI 的情况下指定表。在以前的版本中,RetrofitModel 选项将弹出一个对话框,允许用户选择要包含在模型中的表。 ConceptualEdmGen dll 现在有两个额外的公共方法,可以在不弹出对话框的情况下设置表列表 - 一个从文件中提取表列表,另一个将表列表作为列表直接提供给该方法。字符串。
包中出现的 EdmGen2 代码使用“from file”选项,它在当前目录中查找名为“Tables.txt”的文件,如果找到,则将其内容提供给 dll 以设置表列表。例如,如果文件“Tables.txt”的内容如下:
EdmGen2 将为 AdventureWorks 的 HumanResources 架构中的所有表生成(对于 RetrofitModel 选项)模型。对于这两种方法,空列表将导致数据库中的所有表都添加到模型中。如果两个表选择方法都没有被调用,表选择 UI 仍然会出现。
The tupleFraction parameter helps define what it means to be a "significant" subclass. The data mining rules are heuristics, and as such they can potentially find patterns where common sense might not agree.
The tupleFraction parameter says this (for some of the rules): if EdmGen++ thinks that it has found a subclass, but the new subclass has less than tupleFraction of the instances from its parent class, consider the new subclass "insignificant" and don't create it. The parameter is optional - if you don't specify it, I think that it gets set to 0.05 (5%).
The current version only allows table specification through the UI. However, to pull the list of tables from a file or from some other source is an easy addition - I will add it to the top of the to-do list for the next version.
UPDATE: We have updated the code at code.msdn.microsoft.com/edmgen2 to allow for tables to be specified without the GUI. In the previous version, the RetrofitModel option would bring up a dialog that would allow the user to choose the tables to include in the model. The ConceptualEdmGen dll now has two additional public methods that can set the list of tables without bringing up a dialog – one that pulls the list of tables from a file, and one where the list of tables is fed directly to the method as a list of strings.
The EdmGen2 code as it appears in the package uses the “from file” option, where it looks for a file called “Tables.txt” in the current directory, and if found, feeds its contents to the dll to set the list of tables. So for instance, if the following were the contents of the file “Tables.txt”:
EdmGen2 would generate (for the RetrofitModel option) a model for all of the tables in the HumanResources schema for AdventureWorks. For both methods, an empty list will result in all tables in the database being added to the model. The table selection UI will still appear if neither table selection method is called.
的回复。
Alex James
我刚刚向负责 EdmGen2 的人员发送了一封电子邮件,让我们看看他与Microsoft 实体框架团队项目经理
I've just sent an email to the guy responsible for EdmGen2 lets see what he comes back with
Alex James
Program Manager, Entity Framework Team, Microsoft.
我的解决方案是创建 EdmGen2 的变体,它读取 Filters.txt 文件,该文件不仅包含表名,还包含解析为 EntityStoreSchemaFilterEntry 参数(类别、架构、名称、ObjectType、FilterEffect)的文本。这使我能够生成对特定视图和表进行操作的模型和程序集 - 我认为 EdmGen2 无法做到这一点。
当然,这不适用于 ConceptualEdmGen,但由于没有可用的源代码,所以我选择不使用该组件。
我尚未解决的一个问题是如何将存储过程的函数定义正确地注入到 CSDL 和 MSL 中。我在 SSDL 中有它,但还不知道如何做其他的。
My solution to this was to create a variant of EdmGen2 which reads a Filters.txt file that contains not just table names, but text that gets parsed into EntityStoreSchemaFilterEntry parameters (Category, Schema, Name, ObjectType, FilterEffect). This allows me to generate models and assemblies which operate on specific views as well as tables - something that I don't think EdmGen2 does.
Of course that doesn't work with the ConceptualEdmGen, but since there is no source available for that I've elected not to use that component anyway.
One problem that I haven't solved is how to properly inject function definitions for stored procs into CSDL and MSL. I have it in SSDL but don't know yet how to do the others.