How to: Add a Creator Method

A Creator method adds new data to the data source of an entity. The Business Data Connectivity (BDC) service calls this method when users click the New Item button on the Ribbon of a list that is based on the model. For more information, see Designing a Business Data Connectivity Model.

To add a Creator 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 Creator Method.

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

    • A method named Create.

    • 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 Creator method that adds data to the data source. The following example adds a new contact to the AdventureWorks sample database for SQL Server.

    NoteNote

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

    
    public static Contact Create(Contact newContact)
    {
        const string ServerName = "MySQLServerName";
        AdventureWorksDataContext dataContext = new AdventureWorksDataContext
              ("Data Source=" + ServerName + ";" +
               "Initial Catalog=AdventureWorks;Integrated Security=True");
    
        Contact contact = new Contact();
    
        contact.FirstName = newContact.FirstName;
        contact.LastName = newContact.LastName;
        contact.EmailAddress = newContact.EmailAddress;
        contact.Phone = newContact.Phone;
        contact.EmailPromotion = newContact.EmailPromotion;
        contact.NameStyle = newContact.NameStyle;
        contact.PasswordHash = newContact.PasswordHash;
        contact.PasswordSalt = newContact.PasswordSalt;
        contact.ModifiedDate = DateTime.Now;
        contact.rowguid = Guid.NewGuid();
    
        dataContext.Contacts.InsertOnSubmit(contact);
        dataContext.SubmitChanges();
        return contact;
    
    }
    
    
    
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft