Freigeben über


Developing with Concrete Data Types

The Microsoft Multi-Channel Commerce Foundation provides you with the ability to support a fully strongly typed approach to the model by using developer maintained concrete data types. You can view these data types as wrappers around the generic Commerce Server 2009 commerce entities if they implement a special interface called ICommerceEntity. 

Dd451701.6f2a7784-724b-4086-9297-b7f3c197c6e0(en-US,CS.90).gif

Request builders use this interface to build the message to send to the Commerce Server 2009 service. Internally, as part of the wrapper class, strongly typed properties simply reference data stored in the CommerceEntity.CommercePropertyCollection. For example, the "wrapper" class for a UserProfile would look like:

public class UserProfile : ICommerceEntity
{
    private CommerceEntity _commerceEntity;
    public const string ModelNameDefinition = "UserProfile";
    public UserProfile()
    {
        this._commerceEntity = new CommerceEntity(UserProfile.ModelNameDefinition);
    }
    public UserProfile(CommerceEntity commerceEntity)
    {
        this._commerceEntity = commerceEntity;
    }
    public string Email
    {
        get { return this._commerceEntity.GetPropertyValue(PropertyName.Email) as string; }
        set { this._commerceEntity.SetPropertyValue(PropertyName.Email, value); }
    }
    public string Id
    {
        get { return this._commerceEntity.Id; }
        set { this._commerceEntity.Id = value; }
    }
    public string ModelName
    {
        get { return this._commerceEntity.ModelName; }
        set { this._commerceEntity.ModelName = value; }
    }
    public CommercePropertyCollection Properties
    {
        get { return this._commerceEntity.Properties; }
        set { this._commerceEntity.Properties = value; }
    }
    public CommerceEntity ToCommerceEntity()
    {
        return this._commerceEntity;
    }
    public class PropertyName : CommerceEntity.PropertyName
    {
        public const string Email = "Email";
    }
    public static implicit operator UserProfile(CommerceEntity commerceEntity)
    {
        System.Diagnostics.Debug.Assert(commerceEntity.ModelName.Equals(UserProfile.ModelNameDefinition));
        return new UserProfile(commerceEntity);
    }
}

Note

The implicit cast operator is provided so that the CommerceEntity objects returned in a CommerceResponse can easily be converted to the fully typed wrapper class.

You can now perform a query by using the fully typed wrapper class as follows:

var query = new CommerceQuery<UserProfile>();
query.SearchCriteria.Model.Email = "useremail@yourcompany.com";

See Also

Other Resources

Commerce Foundation Objects and Models

Commerce Foundation CommerceEntity

Commerce Foundation Operations