问题
This question is part of my following one I already asked roughly 2.5 years ago: Entity Framework (.NET) Round-Trip Modelling with Model First?
I wanted to ask if in the meantime, the following is possible (and from which version of EF upwards):
We are currently using EF 5.0 with the "Model First" approach (VS 2012). After first problems, we managed to configure the two T4 templates for generating the DbContext-derived class and the POCOs so that if we need to map a new (or existing) database table, we can do that via right-clicking into the VS EF designer > "update model from database..." all works well (our DB has many tables and my EF model doesn't map all of them).
Now we have some other (POCO) classes which are not yet mapped to entities (in the designer/edmx) AND we do not have any tables in the database for them. Using the "model first" approach (we used so far), is it possible to generate both, the the table schemata (we need the generated SQL as well) in the database and the entities in the designer/edmx (meta-data)? (I know the name "model first" may say it, but maybe the same applies as the link for "code first" in the next section says: "edmx based" should have been better?)
I know "code first" (or better: "code based", http://blogs.msdn.com/b/adonet/archive/2014/10/21/ef7-what-does-code-first-only-really-mean.aspx) can do such things, but as far as I know, the mappings then are only created temporarily in virtual memory, instead of in the edmx (which is, what we need).
One idea I have is to create an additional mini-project using code first, generate the db tables, and from these, update my edmx in our project mentioned above; or is it possible to somehow write out an edmx from the temporary model generated by code first?
Would be great if anyone knows a more elegant solution,
thanks in advance.
Helpful articles from Arthur Vickers:
http://blog.oneunicorn.com/2012/02/26/dont-use-code-first-by-mistake/
http://blogs.msdn.com/b/adonet/archive/2011/03/07/when-is-code-first-not-code-first.aspx
The following SO threads are good matches, too, but somewhat old, too (EF 4):
Using EF4 migration tool with model-first approach
Entity Framework 4.1 Code First EDMX issue
来源:https://stackoverflow.com/questions/28728145/ef-model-first-create-entity-in-edmx-and-db-table-from-class