Jaa


How to Use Multiple-Valued Profile Properties

For the latest version of Commerce Server 2007 Help, see the Microsoft Web site.

Multiple-valued profile properties store more than one value in a single SQL Server database column. For example, the list of credit cards for a user is stored in the u_credit_cards field in the UserObject table as a semicolon-delimited list of GUID key values.

Note

Only six values can be stored in the u_credit_cards database field without modifying the database schema. This is because a single GUID value, that includes brackets, dashes, and the semicolon delimiter, uses thirty-nine bytes and the default field is defined as NVARCHAR(255).

To use the Commerce Server runtime to create multiple-valued fields

  1. Create a procedure to encapsulate the code that you will write.

  2. Within the procedure, create an instance of the ProfileContext object.

  3. Create an organization profile by calling the CreateProfile method of the ProfileContext object.

  4. Update the GeneralInfo.address_list property using an object array.

  5. Set the GeneralInfo.name property.

  6. Update the profile by calling the Update method.

To use the Commerce Server Profiles Web Service to create multiple-valued fields

  1. Create a procedure to encapsulate the code that you will write.

  2. Within the procedure, create an instance of the ProfileManagementContext object.

  3. Create an XML representation of an organization profile.

  4. Convert the XML string to an XML document.

  5. Create the profile by calling the CreateProfile method on the Profiles Web service, passing it the XML document that you created in the step 4.

Example

The following code example shows how to access the Commerce Server runtime to set a multiple-value address list for an organization profile.

private void MultiValue_Runtime(string orgGuid1, string orgGuid2)
{
    // Get Profiles runtime object.
    ProfileContext ctxtRuntime = CommerceContext.Current.ProfileSystem;

    // Create a new organization profile object.
    Profile orgProfile = ctxtRuntime.CreateProfile(Guid.NewGuid().ToString("B"), "Organization");

    // Update organization address_list property to include multiple values.
    orgProfile.Properties["GeneralInfo.address_list"].Value = new object[] {orgGuid1, orgGuid2};
    orgProfile.Properties["GeneralInfo.name"].Value = "MyOrganization";
    orgProfile.Update();
}

The following code example shows how to access the Commerce Server Profiles Web service to perform the same operation as the prior example.

private void MultiValue_WebService(string orgGuid1, string orgGuid2)
{
    // Declare variables.
    String xmlData = "";
    XmlDocument profileXMLDoc = new XmlDocument();
    String myGUID = Guid.NewGuid().ToString();

    // Access Profiles Web service.
    ProfileManagementContext ctxtWS = ProfileManagementContext.Create("https://localhost/ProfilesWebService/ProfilesWebService.asmx");

    // Create XML representation of the organization profile.
    xmlData += @"<ProfileDocument>";
    xmlData += @"   <Organization>";
    xmlData += @"<GeneralInfo>";
    xmlData += @"<org_id>" + myGUID + "</org_id>";
    xmlData += @"           <name>myOrganization</name>";
    xmlData += @"           <address_list>" + orgGuid1 + "</address_list>";
    xmlData += @"           <address_list>" + orgGuid2 + "</address_list>";
    xmlData += @"</GeneralInfo>";
    xmlData += @"</Organization>";
    xmlData += @"</ProfileDocument>";

    // Load the XML string into an XML document.
    profileXMLDoc.LoadXml(xmlData);

    // Create the XML Profile, converting the XMLDocument to an XMLElement.
    ctxtWS.CreateProfile(profileXMLDoc.DocumentElement);
}

See Also

Other Resources

How to Access Embedded Profiles

Profiles Concepts and Tasks

Developing with the Profiles System