Get contact with facets
You must specify which facets should be returned with a contact or batch of contacts by passing an array of facet keys into the ContactExpandOptions. The only facets that are always returned if they exist are ConsentInfo and MergeInfo.
In the following example, the default EmailAddressList and AddressList facets are requested as part of the contact expand options:
A facet is added to the contact’s Facets dictionary if the facet exists for that contact. If the facet you requested is not defined in the model xConnect will throw an exception when the request is executed. When the contact or contacts have been returned, use the .GetFacet<T>() method on the contact to retrieve the facet object:
The method .GetFacet<T>() will return null if:
-
The facet was not requested as part of the
ContactExpandOptionswhen the contact was initially retrieved -
The facet has not set for a particular contact
-
The combination of type and key is incorrect
The following example demonstrates how to retrieve and work with the EmailAddressList facet:
All built-in facet models have a DefaultFacetKey property - for example, WebVisit.DefaultFacetKey.
Get facets using the default facet key
All built-in facet models have a FacetKey attribute that associates the default facet key with the facet model.
If a facet key is not specified, xConnect will fall back to the default value. Add the FacetKey attribute to your own facet models to mimic this behavior. In the following example, .Expand<EmailAddressList>() and .GetFacet<EmailAddressList>() are used without specifying a facet key.
An exception will be thrown if the facet model does not have a FacetKey attribute.
If you have used a facet model (such as EmailAddressList) to define multiple facets, consider storing the non-default facet keys as constants in your model class.
Setting or updating facets
You must use the .SetFacet() extension method to update facets. For more information, see: Set a contact facet.