Database Reference
In-Depth Information
Our model has just one entity: Customer. The conceptual layer (CSDL mapping layer (MSL and storage layer
(SSDL definitions are typically found in the .edmx file in your project. We want to read these definitions from a
database. To read these definitions from a database, do the following:
1.
Right-click the design surface, and view the Properties. Change the Code Generation
Strategy to None. We'll use POCO for our Customer class. See Chapter 8 for more recipes
on using POCO.
2.
Create the table shown in Figure 7-2 . This table will hold the definitions for our project.
Figure 7-2. The Definitions table holds the definitions for our SSDL, CSDL, and MSL. Note that the column data types
for the definitions are XML
3.
Right-click the design surface, and view the Properties. Change the Metadata Artifact
Processing to Copy to Output Directory. Rebuild your project. The build process will create
three files in the output directory: Recipe2.ssdl , Recipe2.csdl , and Recipe2.msl .
4.
Insert the contents of these files into the Definitions table in the corresponding columns.
Use 1 for the Id column.
5.
Follow the pattern in Listing 7-2 to read the metadata from the Definitions table, and
create a MetadataWorkspacethat your application will use.
Listing 7-2. Reading the Metadata from the Definitions Table
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Metadata.Edm;
using System.Data.SqlClient;
using System.Data.EntityClient;
using System.Xml;
using System.Data.Mapping;
using System.Data.Objects;
namespace Recipe2
{
class Program
{
static void Main(string[] args)
Search WWH ::




Custom Search