Create a new Entity Data Model (EDM) with the Entity Framework's EDM Wizard
DevForce developers begin entity model development by defining an Entity Framework Entity Data Model (EDM). You create a new EDM using the Entity Framework EDM Wizard.
In this topic we show most of what you need to use the EDM Wizard but it's also worth looking at Microsoft's documentation in MSDN
The first question it "where do I put the model?". You have to pick the project that will be home to your entity class model.
The DevForce tutorials teach you to begin with a DevForce n-tier template and add the model to the web application server project. That's a simple way to learn DevForce. Although not ideal in the long term, don't worry about it now; you can break that model into a separate project later if you want to.
More experienced DevForce developers create a dedicated model project up front. Make sure you create the model project as a .NET 4.5 class library.
Either way, you'll add your entity model classes to a .NET 4.5 project. Entity models may not be directly defined in Silverlight and mobile projects.
Having decided upon the project that will hold your model, do the following:
You have launched the "Entity Data Model Wizard".
The wizard offers two ways forward:
Do you want to generate the entity model from an existing database? Choose #1 and follow the "Data First" path. Most developers go this way, either because they are committed to a legacy database or because they prefer to define the database and the entity model at the same time.
You might prefer #2 - "Model First" - if you are building the application from scratch, have no legacy database to worry about, and want to delay defining a database until you've worked out your entity model.
Both approaches produce a Conceptual Entity Model that defines the shapes and relationships among the entities that will eventually become your entity classes.
"Data First" produces a full EDM that maps the Conceptual Model to the Storage Model. The Storage Model describes the database schema; the mapping correlates the Conceptual Entities with tables and columns in storage. This full EDM is required by the Entity Framework to read and write to the database.
The "Model First" approach yields an EDMX without mapping and storage descriptions. You can add the Storage Model and Mapping later but until you do you won't be able to access a database with this EDM.
DevForce is OK with that. DevForce only needs the Conceptual Model to generate entity classes. You can develop and test your application quite effectively using an offline entity cache or a fake backing store populated with dummy data.
When you choose "Empty model", the wizard generates a skeletal EDMX file and sends you straight to the EDM Designer with a blank canvas. The EDM wizard has done its job. You proceed to manually add entities and associations to the Conceptual Model.
In the "Data First" approach, you point the Wizard at an existing database and tell it to generate entities corresponding to selected tables and views. This is by far the most common approach to entity modeling.
First you must identify the database that will be the schema source.
This needn't be the production database; in fact it should not be. Pick a version of the database with a suitable schema; it should be a database you can read to and write from during development.
The wizard asks you to pick a database connection as in this example:
Your target database will be in the drop-down list if you've previously created a connection to it in Visual Studio. The "Server Explorer" window reveals the connections known to Visual Studio at the moment:
If the target database is not in the list, press the New Connection... button to open the Visual Studio "Connection Properties" dialog. This screenshot shows the default connection in SQL Server for the "NorthwindIB" tutorial database as it was installed with DevForce.
If using Visual Studio 2013, or the EF 6 Power Tools are installed with VS2012, you'll also be prompted to choose the EF version:
As of DevForce version 7.2.2, you may choose either version 5 or 6 for your model. If using an earlier version of DevForce, only EF 5 is supported.
The wizard connects to the database you picked and reads the database schema. This can take from seconds to minutes. Eventually it presents an "Choose objects" dialog with a list of database objects categorized by "Tables", "Views", and "Stored Procedures". In the example shown in the following screenshot, the developer is modeling tables:
Some observations:
When you press Finish, the wizard generates the EDM and hands off to the EDM Designer.