Similarly add the other methods from the Add a Method drop-down list. After adding all the Methods the BDC Explorer looks like the following one.
In the CustomerService class, replace the code with the following one.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BdcModel;
namespace BdcModel.BdcModel1
{
public partial class CustomerService
{
public static Customer ReadItem(int customerID)
{
const string ServerName = @"UKCBEMTSEKIKM01\INSQL01";
LINQtoSQLDataContext dataContext = new LINQtoSQLDataContext
("Data Source=" + ServerName + ";" +
"Initial Catalog=Customer_Details;Integrated Security=True");
Customer custometer =(from customers in dataContext.Customers.AsEnumerable().Take(20)
where customers.CustomerID == customerID
select customers).Single();
return custometer;
}
public static IEnumerable<Customer> ReadList()
{
const string ServerName = @"UKCBEMTSEKIKM01\INSQL01";
LINQtoSQLDataContext dataContext = new LINQtoSQLDataContext
("Data Source=" + ServerName + ";" +
"Initial Catalog=Customer_Details;Integrated Security=True");
IEnumerable<Customer> cust =
from customers in dataContext.Customers.Take(20)
select customers;
return cust;
}
public static Customer Create(Customer newCustomer)
{
const string ServerName = @"UKCBEMTSEKIKM01\INSQL01";
LINQtoSQLDataContext dataContext = new LINQtoSQLDataContext
("Data Source=" + ServerName + ";" +
"Initial Catalog=Customer_Details;Integrated Security=True");
dataContext.Customers.InsertOnSubmit(newCustomer);
dataContext.SubmitChanges();
Customer cust = dataContext.Customers.Single(c => c.CustomerID == newCustomer.CustomerID);
return cust;
}
public static void Delete(int customerID)
{
const string ServerName = @"UKCBEMTSEKIKM01\INSQL01";
LINQtoSQLDataContext dataContext = new LINQtoSQLDataContext
("Data Source=" + ServerName + ";" +
"Initial Catalog=Customer_Details;Integrated Security=True");
Customer cust = dataContext.Customers.Single(c => c.CustomerID == customerID);
dataContext.Customers.DeleteOnSubmit(cust);
dataContext.SubmitChanges();
}
public static void Update(Customer customer)
{
const string ServerName = @"UKCBEMTSEKIKM01\INSQL01";
LINQtoSQLDataContext dataContext = new LINQtoSQLDataContext
("Data Source=" + ServerName + ";" +
"Initial Catalog=Customer_Details;Integrated Security=True");
Customer cust = dataContext.Customers.Single(c => c.CustomerID == customer.CustomerID);
cust.CustomerID = customer.CustomerID;
cust.FirstName = customer.FirstName;
cust.LastName = customer.LastName;
dataContext.SubmitChanges();
}
}}