开发者

How can I use the EntityModelSchemaGenerator to generate less then my entire model?

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 开发者_JS百科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?


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:

EdmGen2 /RetrofitModel "Server=(local);Integrated Security=true;Initial Catalog=AdventureWorks;" "System.Data.SqlClient" "AVWorks"

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.


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

HumanResources.Department
HumanResources.Employee
HumanResources.EmployeeAddress
HumanResources.EmployeeDepartmentHistory
HumanResources.JobCandidate
HumanResources.Shift

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.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜