Database Reference
In-Depth Information
try
{
// Open connection
conn.Open();
// Execute query via ExecuteReader
SqlDataReader rdr = cmd.ExecuteReader();
}
Assume you have deployed the preceding code into production along with the database, which has
the column names as specified in the select query. Later, the database administrator (DBA) decides to
change the column names in all the tables to implement new database policies: the DBA modifies the
Production.Product table and changes the Name column to ProductName and the ProductNumber
column to ProductSerialNumber.
After these database changes are made, the only way to prevent the application from breaking is by
modifying all the code segments in the source code that refer to the Name and ProductName columns,
rebuilding, retesting, and deploying the whole application again. So, the modified code segment in the
preceding code will appear as follows:
// Create command
string sql = @"select ProductName, ProductSerialNumber
from Production.Product";
Though on the surface it seems not so difficult to make such changes, if you factor in the possibility
that there might be many database-related code segments that require modification of the column
names according to the new column naming scheme, this can end up being a tedious and difficult
approach to upgrade an application so it can work with the modified database.
With ADO.NET EF 5.0's Entity Data Model, Microsoft has made entity-relationship modeling
executable. Microsoft achieved this by a combination of XML schema files and ADO.NET EF 5.0 APIs.
The schema files are used to define a conceptual layer to expose the data store's schema (for example,
the schema for a SQL Server 2012 database) and to create a map between the two. ADO.NET EF 5.0
allows you to write your programs against classes that are generated from the conceptual schema. The
EDM then takes care of all of the translations as you extract data from the database by allowing you to
interact with that relational database in an object-oriented way.
The EDM makes it possible for the client application and the database schema to evolve
independently in a loosely coupled fashion without affecting or breaking each other.
The EDM of ADO.NET 5.0 Entity Framework provides a conceptual view of the database schema
that is used by the application. This conceptual view is described as an XML mapping file in the
application. The XML mapping file maps the entity properties and associated relationships to the
database tables.
This mapping is the magic wand that abstracts the application from the changes made to the
relational database schema. So, rather than modifying all the database-oriented code segments in an
application to accommodate changes made in the database schema, you just need to modify the XML
mapping file in such a way that it reflects all the changes made to the database schema. In other words,
the solution offered by ADO.NET 5.0 EDM is to modify the XML mapping file to reflect the schema
change without changing any source code.
 
Search WWH ::




Custom Search