Skip to content
This repository has been archived by the owner on Jun 16, 2024. It is now read-only.

Support for UpsertRequest And KeyAttributeCollection of Composite Keys #521

Open
michaelfsarkis opened this issue Sep 24, 2020 · 4 comments

Comments

@michaelfsarkis
Copy link

Hi,

I am not sure if the framework support the scenario of using anUpsertRequest And KeyAttributeCollection of Composite Keys.
I have tried to implement to test it, but I got a full load of duplicates. Was not sure if it was my code, or the scenario I am using is unsupported. My code below:

var MyMetadata = new Microsoft.Xrm.Sdk.Metadata.EntityMetadata();
            DAMetadata.LogicalName = new_testEntity.EntityLogicalName;
            var alternateKeyMetadata = new Microsoft.Xrm.Sdk.Metadata.EntityKeyMetadata
            {
                KeyAttributes = new string[] { "new_mobilenumber", "new_birthdate" }
            };
            MyMetadata.SetFieldValue("_keys", new Microsoft.Xrm.Sdk.Metadata.EntityKeyMetadata[]
                {
                    alternateKeyMetadata
                });

var context = new XrmFakedContext();
            context.Initialize(entities);
            context.InitializeMetadata(DAMetadata);

Please advise

@BetimBeja
Copy link
Contributor

Hello @michaelfsarkis,
the framework support for Alternate Key is limited at the "retrieval" of the data (internally it converts the Alternate Key to the record GUID), but it does not yet support an uniqueness check. I am not sure if the uniqueness check is what you mean with I got a full load of duplicates. It does support composite keys too.

@michaelfsarkis
Copy link
Author

Thanks @BetimBeja for the prompt response.

Yes, I meant uniqueness check. When calling the UpsertRequest, and passing Alternate key, I was expecting the framework to update existing record (with the same key values), instead of creating duplicate record (with similar key values).

I understand now that Composite keys are supported but uniqueness check is not yet.

Does framework support "UpsertRequest" for uniqueness check if I used EntityId (Guid) instead of Alternate Key?

@BetimBeja
Copy link
Contributor

Can you please provide a sample unit test of what you are trying to achieve?
As I mentioned the framework supports the "retrieval" of data (for the UpsertRequest it is implemented here) so if the test is setup correctly it should not duplicate record but update existing ones.

@BetimBeja
Copy link
Contributor

@michaelfsarkis any updates?
I think you should close the issue if it is resolved for you...

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants