简体   繁体   中英

What to do in Dynamics365 web api when property on object doesnt exists?

Lets asume we have a Account entity in Dynamics 365, account have c5 number and name attributes.

Now i want to create a new account through the dynamics 365 Web API. I create an account object with c5 number, name and i add an aditional attribute lastname. When i post this account object to Web API, i will get an error like :

    "code":"","message":"The property 'lastname' does not exist on type 'Microsoft.Dynamics.CRM.account'. Make sure to only use property names that are defined by the type.","innererror":{

  "message":"The property 'lastname' does not exist on type 'Microsoft.Dynamics.CRM.account'. Make sure to only use property names that are defined by the ...

I really dont uderstand why Dynamics 365 Web API just cant ignore property's which it cant use?

At this specific scenarion it means that if we delete name property on the account entity, there are possibility that all our systems which talks to the Web API will crash.

How can i get around this problem? Are there anyway to force dynamics 365 Web API to ignore some propertys?

Web Api not only do not ignore not used values, but even on update, it updates all values You send, even they are equal. As one step can be - ignore this value by setting it to non NonSerialized, it will be excluded. Also, You can define naming to class members, so You do not have to worry about how they are named in code.

`[Serializable]
public class Account    {
    [NonSerialized]
    public string lastname;

    [JsonProperty("firstname")]
    public string firstName;

    [JsonProperty("index")]
    public int c5;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM