Export (0) Print
Expand All

How to: Add a Deleter Method

You can enable an end user to delete a data record from an external list on a SharePoint site by adding a Deleter method to the model. For more information, see Designing a Business Data Connectivity Model.

To create a Deleter method

  1. On the BDC designer, select an entity.

  2. On the View menu, click Other Windows, and then click BDC Method Details.

    The BDC Method Details window opens. For more information about the BDC Method Details window, see BDC Model Design Tools Overview.

  3. In the BDC Method Details window, from the Add a Method drop-down list, select Create a Deleter Method.

    Visual Studio adds the following elements to the model. These elements appear in the BDC Method Details window.

    • A method named Delete.

    • An input parameter for the method.

    • A type descriptor for the parameter.

    • A method instance for the method.

    For more information, see Designing a Business Data Connectivity Model.

  4. In Solution Explorer, right-click the service code file that was generated for the entity, and then click View Code.

    The entity service code file opens in the Code Editor. For more information about the entity service code file, see Creating a Business Data Connectivity Model.

  5. Add code to the Deleter method to delete a record. The following example deletes a line item from a sales order by using the AdventureWorks sample database for SQL Server.

    NoteNote

    The method in this example uses two input parameters.

    NoteNote

    Replace the value of the ServerName field with the name of your server.

    
    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().Take(20)
                where SalesOrderDetails.SalesOrderID == salesOrderID &&
                SalesOrderDetails.SalesOrderDetailID == salesOrderDetailID
                select SalesOrderDetails).Single();
    
        dataContext.SalesOrderDetails.DeleteOnSubmit(SalesOrderDetail);
        dataContext.SubmitChanges();
    }
    
    
    

Community Additions

ADD
Show:
© 2014 Microsoft