SQL Server Primary key not configured on the given database object

l0oc07j2  于 2023-06-28  发布在  其他
关注(0)|答案(1)|浏览(114)

While calling the REST API created by Data API Builder for my stored procedure:

https://localhost:5001/API/pagecustomers/pagesize/10/index/2

I received the error Primary key not configured on the given database object . This is confusing because the stored procedure does not have a primary key. I am passing the proc parameters pagesize and index .

I am using this configuration:

"PageCustomers": {
  "source": {
    "type": "stored-procedure",
    "object": "[dbo].[PageCustomers]",
    "parameters": {
      "PageSize": "",
      "StartIndex": ""
    }
  },
  "permissions": [
    {
      "role": "anonymous",
      "actions": [
        "execute"
      ]
    }
  ],
  "mappings": {
    "Id": "Id",
    "Name": "Name",
    "City": "City",
    "State": "State"
  },
  "rest": {
    "path": "/pagecustomers",
    "methods": [
      "get"
    ]
  },
  "graphql": {
    "operation": "mutation"
  }
},
jucafojl

jucafojl1#

This error is the result of the structure of the url. Slash-separated parameters in the url specify the primary key value(s) of the database object. Instead, when calling stored procedures, parameters are specified in the querystring .

https://localhost:5001/API/pagecustomers?pagesize=10&index=2

With this change, the REST call to the proc works fine.

相关问题