Database Reference
In-Depth Information
Alternatively, you can leverage the more recent Code-First approach to manually create the concrete code
yourself, gaining direct control over the entire process. With Code First, the developer can create entity classes,
mappings and context object, all without the help of a designer. These manually created entity classes, commonly
referred to as POCO, or Plain Old CLR Objects, have no dependence on Entity Framework plumbing. Even more
interesting, the development team can leverage the Entity Framework Power Tool utilities (free download from
Microsoft) to reverse-engineer a Code First model from an existing database, foregoing the effort to have manually
create the entity classes, mappings and context object. The recipes in Chapter 8 show you the basics of creating and
using POCO. Many of the recipes throughout the topic will show you how to use Code First across specific contexts
such as in n-Tier applications.
Visual Studio
Of course, the main tool we use when developing applications for the Windows environment is Visual Studio. This
Integrated Development Environment has evolved over many years from a simple C++ compiler and editor to a
highly integrated, multi-language environment that supports the entire software development lifecycle. Visual Studio
and its related tools and services provide for design, development, unit testing, debugging, software configuration
management, build management and continuous integration, and much more. Don't be worried if you haven't used
all these in your work; few developers have. The point is that Visual Studio is a full-featured toolset. Visual Studio
plays a vital role in the development of Entity Framework applications.
Visual Studio provides an integrated design surface for Entity Framework models. Using this design surface and
other tools in Visual Studio, you can create models from scratch or create them from an existing database. You also
have the option to completely eliminate the designer and manually craft your Entity Types and configuration.
If you have an existing database, which is the case for many of us with existing applications, Visual Studio
provides tools for importing your tables and relationships into a model. This fits nicely with the real world because
few of us have the luxury of developing brand-new applications. Most of us have to extend, maintain, and evolve our
existing code and databases.
Alternately, you can create a model from scratch by starting with an empty design surface and adding new
EntityTypes to the surface, creating both associations and inheritance hierarchies for your model. When you are done
creating the model, right-click the design surface and select Generate Database from Model.
If your project team is code-centric, you can instead create a set of domain classes, including relationships and a
context class and then wire up these classes to hook into the Entity Framework engine and features without having to
use a designer.
Once you have created your model, changes often happen. That's the nature of software development. Visual
Studio provides tools for updating the model from the database. This will keep the model synchronized with changes
in the database. Additionally, the Entity Framework Team also supports a tool called Code First Migrations , which can
be used to keep your database up-to-date with changes in your model.
1-2. Using Entity Framework
Entity Framework is tightly integrated with Visual Studio. To implement Entity Framework in your application, add a
new ADO.NET Entity Data Model in your project. Right-click your project and select Add New Item. In the dialog
box (see Figure 1-4 ), choose the ADO.NET Entity Data Model template. This template is located under the Data
templates. Click Add to launch the Entity Data Model Wizard.
 
Search WWH ::




Custom Search