simple-odata-client / Simple.OData.Client

MIT License
329 stars 196 forks source link

Update ignoring metadata #673

Open despian opened 5 years ago

despian commented 5 years ago

Hi,

Not sure if this is a bug or if I have just missed something but ...

I am able to retrieve and create records no problem. However, when I try to update a record I get the error:

System.Private.CoreLib: Exception while executing function: ProcessReferral. Microsoft.OData.Core: The property 'statuscode' does not exist on type 'Microsoft.Dynamics.CRM.lead'. Make sure to only use property names that are defined by the type or mark the type as open type.

This property does exist in the metadata so I'm not sure what's going wrong here. I have also tried updating other properties but get the same error.

This is the sample code:

public async Task<Lead> UpdateLead(Guid? id, object updates) => await Client
    .For<Lead>()
    .Key(id)
    .Set(updates)
    .UpdateEntryAsync();

...

await CrmService.UpdateLead(lead.LeadId, new
    {
        StatusCode = 1
    }
);

The attached archive contains the Lead class and the metadata. Archive.zip

despian commented 5 years ago

I am able to perform the update by setting OpenType="true" in the metadata.

<EntityType Name="lead" BaseType="mscrm.crmbaseentity" OpenType="true">

But surely this is then just ignoring the metadata. Why is this error happening even though the metadata appears to be correct? Is it something to do with the fact that this entity inherits from a base type?