
312Microsoft Visual Studio 2010: A Beginner’s Guide
public void DeleteCustomer(int custID)
{
var ctx = new MyShopDataContext();
var customer =
(from cst in ctx.Customers where cst.CustomerID == custID select cst)
.SingleOrDefault();
if (customer != null)
{
ctx.Customers.DeleteOnSubmit(customer);
ctx.SubmitChanges();
}
}
}
}
VB:
'NOTE: You can use the "Rename" command on the context
'menu to change the class name "Service1" in both code
'and config file together.
Public Class CustomerService
Implements ICustomerService
Public Function GetCustomer(ByVal custID As Integer) As Customer Implements ICustomerService.GetCustomer
Dim ctx As New MyShopDataContext
Dim customer =
(From cust In ctx.Customers Where cust.CustomerID = custID Select cust).SingleOrDefault()
Return customer
End Function
Public Function GetCustomers() As List(Of Customer) Implements ICustomerService.GetCustomers
Dim ctx As New MyShopDataContext