Databases Reference
In-Depth Information
Figure 20-12. Displaying the Employees Detail form
How It Works
Because you are working with an Entity Data Model, you aren't having to deal with
SqlConnection , SqlCommand , and so forth. Here you create a connection object referencing
the EntityConnection , pass the entire connection string that is stored with the name
NorthwindEntitiesConnectionString in the App.config file, and then open the connection.
EntityConnection connection = new
EntityConnection("name=NorthwindEntitiesConnectionString");
connection.Open();
After specifying opening the connection, it's time to create the Command object using
EntityCommand , and then specify the query to the CommandText property. Notice that the
From clause of the query is composed of EntityContainer.EntitySet , thus including the
name of the connection string, which represents the EntityContainer , suffixed with the
table name, which is actually an EntitySet .
n Note The EntityContainer element is named after the database schema, and all “Entity sets” that
should be logically grouped together are contained within an EntityContainer element. An EntitySet
represents the corresponding table in the database.
EntityCommand command = connection.CreateCommand();
command.CommandText = "select E.FirstName,E.LastName from
NorthwindEntitiesConnectionString.Employees as E";
Search WWH ::




Custom Search