问题
Note: This is not about the difference between Database first, Model first, and Code first.
Microsoft has a number of tools to simplify using DbContext. Unfortunately, there seems to be almost no description and also no documentation on what they are, much less what they do.
What is the difference between:
- Entity Framework Power Tools CTP1
- ADO.NET C# DbContext Generator
- ADO.NET C# POCO Entity Generator
回答1:
I don't usually answer my own questions, but here is what I figured out:
The difference between the ADO.NET C# DbContext Generator
and the ADO.NET C# POCO Entity Generator
is that the former creates a context based on the DbContext
and the latter creates them based on the ObjectContext
.
Basically, these are used in the Model First
and Database First
approaches. The difference between Model First
and Database First
is that in Database First
, you define your data model in the database, then reverse engineer the model (ie. create an .edmx file) from the database. While with Model First
, you create your model in the designer (again, the .edmx file) or by hand, then generate the database from that model.
In both cases, you then generate POCO classes and either a DbContext
or ObjectContext
from the .edmx file.
The Entity Framework Power Tools CTP1
reverse engineers a Code First
model from the database, including POCO class, the DbContext
(don't think it offers ObjectContext
generation) and the mappings (via the OnModelCreating
method).
So what this boils down to is that in Database First
and Model First
, the "model" is defined by the xml .edmx file (or in some cases, several files). While in Code First
, the model is defined using fluent code mappings in OnModelCreating
.
When using the Power Tools to reverse engineer the database, it doesn't create an .edmx file, instead creating the mappings in code. Thus, skipping the xml middle man.
回答2:
ADO.NET C# POCO Entity Generator
exists for a long time and is part of the Mode First approach. Read about it here.
The differences between ADO.NET C# POCO Entity Generator
and ADO.NET C# DbContext Generator
are discussed here: ADO.NET DbContext Generator vs. ADO.NET Poco Entity Generator (ObjectContext).
Entity Framework Power Tools CTP1
is a drop of useful tooling for the project's context menu.
来源:https://stackoverflow.com/questions/7294571/what-is-the-difference-between-that-various-data-templates-microsoft-provides