解决深度插入导航时的错误 属性 Dynamics WebAPI

Resolve error on deep insert of navigation property Dynamics WebAPI

我正在使用 Microsoft Dynamics Web API to write data to an entity in Microsoft Dynamics 365. When I try to do a deep insert 我收到错误消息

An undeclared property 'ccseq_employeeid' which only has property annotations in the payload but no property value was found in the payload. In OData, only declared navigation properties and declared named streams can be represented as properties without values.

为什么我会收到此错误以及如何解决该错误?

JSON

{
    "ccseq_importdate" : "2017-05-28T04:00:00Z", 
    "ccseq_month" : "1", 
    "ccseq_year" : "2017", 
    "ccseq_name" : "Test", 
    "ccseq_status" : "100000000", "ccseq_ccseq_expensetransactionset_ccseq_expensetransaction_ExpenseTransactionSetID" : 
    [ 
        { 
          "ccseq_employeeid@odata.bind": "/systemusers(6d2fd71b-32d1-dd11-a4f5-001a6449bbe7)", 
          "ccseq_clientid@odata.bind": "/ccseq_clients(663ebd00-73b9-4faf-90ed-f56bb9c2dc9b)", 
          "ccseq_navemployeeid" : "11111", 
          "ccseq_employeefirstname" : "John"
        }
    ]
}

ExpenseTransactionSetExpenseTransaction 的父级,这意味着 ExpenseTransaction 可以查找 ExpenseTransactionSetccseq_ccseq_expensetransactionset_ccseq_expensetransaction_ExpenseTransactionSetID 是一对多关系。 systemuserccseq_clients 是在 ExpenseTransaction.

中查找的独立实体

我还在 "ccseq_employeeid@odata.bind"

上尝试了以下变体

我已经看到 question and 问题并尝试了建议的解决方案但没有成功。

在元数据文档{org-url}/api/data/v8.0/$metadata中,您可以检查集合值导航的元素类型属性 ccseq_ccseq_expensetransactionset_ccseq_expensetransaction_ExpenseTransactionSetID吗?

它的导航属性是ccseq_employeeid的同类型吗?如果不是,并且 属性 ccseq_employeeid 属于派生类型,您可能需要将导航 属性 对象注释如下:

{
    "ccseq_importdate" : "2017-05-28T04:00:00Z", 
    "ccseq_month" : "1", 
    "ccseq_year" : "2017", 
    "ccseq_name" : "Test", 
    "ccseq_status" : "100000000",
    "ccseq_ccseq_expensetransactionset_ccseq_expensetransaction_ExpenseTransactionSetID" : 
    [ 
        {
          "@odata.type": "Microsoft.Dynamics.CRM.ccseq_navemployee",
          "ccseq_employeeid@odata.bind": "/systemusers(6d2fd71b-32d1-dd11-a4f5-001a6449bbe7)", 
          "ccseq_clientid@odata.bind": "/ccseq_clients(663ebd00-73b9-4faf-90ed-f56bb9c2dc9b)", 
          "ccseq_navemployeeid" : "11111", 
          "ccseq_employeefirstname" : "John"
        }
    ]
}

我在 this 帖子中找到了答案。深度插入中导航 属性 的正确语法是使用子实体名称,后跟方括号和字段名称。 json需要改成下面的

{
    "ccseq_importdate" : "2017-05-28T04:00:00Z", 
    "ccseq_month" : "1", 
    "ccseq_year" : "2017", 
    "ccseq_name" : "Test", 
    "ccseq_status" : "100000000",
    "ccseq_ccseq_expensetransactionset_ccseq_expensetransaction_ExpenseTransactionSetID" : 
    [ 
        {
          // Next two lines are changed 
          "ExpenseTransaction[ccseq_employeeid@odata.bind]": "/systemusers(6d2fd71b-32d1-dd11-a4f5-001a6449bbe7)", 
          "ExpenseTransaction[ccseq_clientid@odata.bind]": "/ccseq_clients(663ebd00-73b9-4faf-90ed-f56bb9c2dc9b)", 
          "ccseq_navemployeeid" : "11111", 
          "ccseq_employeefirstname" : "John"
        }
    ]
}