Before reading this post, read the previous post: Create an Adventure Works Entity Framework Model
Now that you have created an Entity Framework model for the Adventure Works database, you can begin to update properties to align the model with your business. In this example, I will change a few simple table properties to support future samples that use the model.
To start, open the AdventureWorks.edmx file in the Visual Studio GUI design tool. Select the SalesOrderDetail table by clicking on the table just below the table name in the header. The properties pane should look like this:
The change we are going to make is simple. Change the text in the Entity Set Name field to SalesOrderDetails. Doing this will allow us to differentiate between a single SalesOrderDetail and a set of details in our code and in Intellisense. Do the same thing for SalesOrderHeader, changing the plural value to SalesOrderHeaders. Change the Entity Set Name of the SalesPerson table to SalesPeople.
If you name your database tables with plural names like I do, you will notice one annoying feature of Entity Framework. If you change the Name value, lets say, from SalesPeople to SalesPerson, the designer will automatically change the Entity Set Name to SalesPersonSet. You will need to set it back to your plural value each time.
We will now change the name of the relationships to match our intention. The relationships are found at the bottom of the table under navigation properties. Starting with the SalesPerson table, right click the SalesOrderHeader relationship and select Rename in the context menu. Rename the relationship to SalesOrderHeaders by adding an “s”. In the SalesOrderHeader table, rename the relationshiop SalesOrderDetail to SalesOrderDetails. This is actually the beauty and intent of using the Entity Framework. I recommend seeing what happens when you change column name, table name and other properties as well, but this is all we need to do to support the upcoming samples.
The following code snippet shows how you will reference the newly named properties in code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Models;
namespace ViewModels
{
public class SalesOrderViewModel: ViewModelBase
{
private AdventureWorksEntities context;
private SalesOrderHeader currentSalesOrder;
public SalesOrderViewModel()
{
context = new AdventureWorksEntities();
}
private void SetCurrentSalesOrder(int SalesOrderId)
{
currentSalesOrder = context.SalesOrderHeaders.Where(so => so.SalesOrderId == SalesOrderId).FirstOrDefault();
}
}
}

