fake-xrm-easy icon indicating copy to clipboard operation
fake-xrm-easy copied to clipboard

Support for UpsertRequest And KeyAttributeCollection of Composite Keys

Open michaelfsarkis opened this issue 3 years ago • 4 comments

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

michaelfsarkis avatar Sep 24 '20 05:09 michaelfsarkis

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.

BetimBeja avatar Sep 24 '20 05:09 BetimBeja

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?

michaelfsarkis avatar Sep 24 '20 05:09 michaelfsarkis

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 avatar Sep 24 '20 08:09 BetimBeja

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

BetimBeja avatar Oct 11 '20 20:10 BetimBeja