다음을 통해 공유


Code Snippet: Implementing a Deleter

Applies to: SharePoint Server 2010

In this article
Example for a .NET Connectivity Assembly
Example for an ASP.NET Web Service
Example for a WCF Service
Additional Code Examples

The following code examples show how you can implement a Deleter method instance in a .NET connectivity assembly and in a Web service.

Example for a .NET Connectivity Assembly

public void DeleteCustomer(String id)
{
    Customer customer = GetCustomerByID(id);
    customer.IsDeleted = true;
    customers.Remove(customer); 
}

Example for an ASP.NET Web Service

[WebMethod]
public void DeleteCustomer(String id)
{
    Customer customer = GetCustomerByID(id);
    customer.IsDeleted = true;
    customers.Remove(customer);
}

Example for a WCF Service

The following code shows the operation definition in the service contract interface.

[OperationContract]
void DeleteCustomer(string id);

The following example shows the implementation of the method instance.

public void DeleteCustomer(String id)
{
    Customer customer = GetCustomerByID(id);
    customer.IsDeleted = true;
    customers.Remove(customer);
}

Additional Code Examples

External System—.NET Connectivity Assembly

For example, for the SalesOrder entity in a Microsoft SQL Server database, the Deleter method might look similar to the following.

public static void Delete(int salesOrderID, int salesOrderDetailID)
{
    const string ServerName = "MySQLServerName";
    AdventureWorksDataContext dataContext = new AdventureWorksDataContext
          ("Data Source=" + ServerName + ";" +
           "Initial Catalog=AdventureWorks;Integrated Security=True");

    SalesOrderDetail SalesOrderDetail =
           (from SalesOrderDetails in dataContext.SalesOrderDetails.AsEnumerable()
            where SalesOrderDetails.SalesOrderID == salesOrderID &&
            SalesOrderDetails.SalesOrderDetailID == salesOrderDetailID
            select SalesOrderDetails).Single();

    dataContext.SalesOrderDetails.DeleteOnSubmit(SalesOrderDetail);
    dataContext.SubmitChanges();
}

See Also

Concepts

Implementing a Deleter