I was able to create a virtual entity on a view (I didn't get the error above) - but now I'm getting an error when I retrieve individual rows for the virtual entity. It is really frustrating when documented features do not work.
Dataverse queries to return multiple rows work correctly.
Dataverse queries to return just one row give a primary key error.
Query:
https://exampleenviromment.crm11.dynamics.com/api/data/v9.2/example_entity(2025b5af-2069-ee11-b006-6045bd121e9a)?$select=example_fieldname
Response:
{"error":{"code":"0x80040224","message":"APIM request was not successful : StatusCode : BadRequest, Reason : Primary key is compound by 0 elements but 1 were provided., Response from APIM: {\r\n \"status\": 400,\r\n \"message\": \"Primary key is compound by 0 elements but 1 were provided.\\r\\nclientRequestId: 26bd0a22-d200-4f19-bac8-7f4b7181e54e-self\",\r\n \"error\": {\r\n \"message\": \"Primary key is compound by 0 elements but 1 were provided.\"\r\n },\r\n \"source\": \"sql-ukw.azconn-ukw-001.p.azurewebsites.net\"\r\n}"}}
It appears this is a runtime problem. My underlying view was named vw_example_entity, and querying the table example_entity. If I just rename the table to the name of the view, the call works!
It looks like a clumsy workaroud for now is to ditch views and have my tables prefixed with vw_!
Does anyone know of a way to change the underlying table name in the virtual entity metadata to avoid this?
I've also raised an issue against the documentation, since it suggests this works, and it hasn't for 6 months.