robertb_NZ
Well-known member
I have spent some time working with the tutorial Create web APIs with ASP.NET Core as recommended in my previous query. I'm now trying to generate a client to invoke CICS web service JSPG2 but I'm having trouble with getting my API test to generate.
Program JSPG2 is an operation within service MyJSv, so I generated an API project called MyJSv and I'm trying to create a controller for JSPG2 within this. Program JSPG2 is invoked by posting input message IJSPG2, and responds with an output message OJSPG2. From my SoapUI tests I had example JSON for the input and output messages, and I've created classes IJSPG2.cs and OJSPG2.cs in the Models folder. I added and registered a database context. So far so good.
Now I reach the tutorial stage Scaffold a Controller. I select API Controller with actions, using Entity Framework and, in the dialog, selected
Model Class IJSPG2 (MyJSv.Models)
Data Context Class: JSPG2Context (MyJSv.Models)
Visual Studio reacted with an error: -
This error persisted even after I added [Key] to the definition. IJSPG2.cs is defined
Where do I go from here? I'm wondering if I should have used "API Controller, Empty" or perhaps "API Controller with actions" instead of "API Controller with actions, using Entity Framework". Also, do I need to have all the database context of the tutorial for the situation where all I want to do is to send IJSPG2 as a json request message, and handle a json response which can be formatted to OJSPG2. Using database code, even in memory, seems to me to be unnecessary overhead even if I can get it to work.
Thank you for helping, Robert.
Program JSPG2 is an operation within service MyJSv, so I generated an API project called MyJSv and I'm trying to create a controller for JSPG2 within this. Program JSPG2 is invoked by posting input message IJSPG2, and responds with an output message OJSPG2. From my SoapUI tests I had example JSON for the input and output messages, and I've created classes IJSPG2.cs and OJSPG2.cs in the Models folder. I added and registered a database context. So far so good.
Now I reach the tutorial stage Scaffold a Controller. I select API Controller with actions, using Entity Framework and, in the dialog, selected
Model Class IJSPG2 (MyJSv.Models)
Data Context Class: JSPG2Context (MyJSv.Models)
Visual Studio reacted with an error: -
There was an error running the selected code generator:
The entity type 'IJSPG2' requires a primary key to be defined.
If you intended to use a keyless enitity type call 'HasNoKey0'
This error persisted even after I added [Key] to the definition. IJSPG2.cs is defined
C#:
using System.ComponentModel.DataAnnotations;
namespace MyJSv.Models
{
public class IJSPG2
{
public string JZ_Function { get; set; }
public int JZ_Employee_Skip { get; set; }
public class JZEmployee
{
[Key] public string EMPNO { get; set; }
public string FIRSTNME { get; set; }
...
public string JZ_CURRENCY { get; set; }
}
public class ViewState
{
public string CheckSum_Employee { get; set; }
}
}
}
Where do I go from here? I'm wondering if I should have used "API Controller, Empty" or perhaps "API Controller with actions" instead of "API Controller with actions, using Entity Framework". Also, do I need to have all the database context of the tutorial for the situation where all I want to do is to send IJSPG2 as a json request message, and handle a json response which can be formatted to OJSPG2. Using database code, even in memory, seems to me to be unnecessary overhead even if I can get it to work.
Thank you for helping, Robert.