Ang pag-access sa pahinang ito ay nangangailangan ng pahintulot. Maaari mong subukang baguhin ang mga direktoryo.
Use an alternate key to reference a record
You'll use alternate keys with data integration scenarios to perform data operations where you don't know the primary key value of a Dataverse record. You can only use alternate keys for tables where they're defined. Most Dataverse tables won't have alternate keys unless they have been customized to include them.
To understand how to define and identify alternate keys for a table, see the following articles:
When you use the Web API, you reference a specific record using a URL and then use the POST, PATCH, or DELETE Http methods to perform the data operation. You also use URLs to set values for single-valued navigation properties using the @odata.bind syntax, or as parameters to functions and actions.
The following table provides examples showing how to reference records using relative urls:
Situation
Example
With a primary key
/accounts(00000000-0000-0000-0000-000000000001) OR accounts(accountid=00000000-0000-0000-0000-000000000001) See following note about systemuser and team entity types
/accounts(_primarycontactid_value=00000000-0000-0000-0000-000000000002) When an alternate key is defined for a lookup column, you must use the name of the corresponding Lookup Property. A lookup property follows the following naming convention: _<name of single-valued navigation property>_value.
Note
Because of how systemuser and team entity types inherit from the principal entity type, you cannot use a named primary key to reference these entities. The primary keys for both of these entities is ownerid, rather than systemuserid or teamid. The principal entity type doesn't support GET operations. More information: EntityType inheritance
Exceptions when using alternate keys with the Web API
You have to be aware of the following conditions and possible exceptions when using alternate keys:
If you specify a column that isn't defined as a unique key, an error is thrown indicating that use of unique key columns is required. The error message is: The key in the request URI is not valid for resource 'Microsoft.Dynamics.CRM.<table logical name>'. Ensure that the names and number of key properties match the declared or alternate key properties for the resource 'Microsoft.Dynamics.CRM.<table logical name>'.
Alternate key values with the following characters /,<,>,*,%,&,:,\\,?,+ aren't currently supported.
When you use the SDK for .NET, there are two ways to use alternate keys.
Using the Entity class
When you create an instance of the Entity class you can specify the keys to use to identify the record using the following Entity Constructors:
// For use with the primary key
public Entity (string logicalName, Guid id) {…}
// For use with a single alternate key value
public Entity (string logicalName, string keyName, object keyValue) {…}
// For use with multiple alternate key values
public Entity (string logicalName, KeyAttributeCollection keyAttributes) {…}
// For use with the primary key
public EntityReference(string logicalName, Guid id) {…}
// For use with a single alternate key value
public EntityReference(string logicalName, string keyName, object keyValue) {…}
// For use with multiple alternate key values
public EntityReference(string logicalName, KeyAttributeCollection keyAttributeCollection) {…}
You can use EntityReference to set values for entity lookup columns. When used to set a lookup column, the key values are used to find the primary key value, and the primary key values is stored in the database.
You can use EntityReference for messages that use this type as a property, such as Delete using the DeleteRequest class.
Exceptions when using alternate keys with the SDK for .NET
You have to be aware of the following conditions and possible exceptions when using alternate keys:
If the key columns are provided, the system attempts to match the set of columns provided with the keys defined for the Entity. If it doesn't find a match, it throws an error. If it does find a match, it validates the provided values for those columns. If valid, it retrieves the primary key value of the record that matched the provided alternate key values, and populate the Entity.Id property or EntityReference.Id Property with this value.
If you specify a column that isn't defined as a unique key, an error is thrown indicating that use of unique key columns is required.