1. Olivier PAVLIN
  2. SnapDevelop
  3. Wednesday, 13 November 2019 11:20 AM UTC
Hello,
 
I try to migrate some of my PB2017 project to a web api, in my model generate with my datawindow i have a 'Clients' table with a primary key ID as string value called "Cd_Cl".
 
Here is the generated model:

    public class Dw_Clients
    {
        [Key]
        [DefaultValue(typeof(String), "'0'")]
        public String No_Ste { get; set; }

        [Key]
        public String Cd_Cl { get; set; }

        [ConcurrencyCheck]
        public String Vil { get; set; }

        [ConcurrencyCheck]
        public String Des_Cl { get; set; }

    }
 
In my service i wrote these two methods based on the tutorial :
 
  public IDataStore Retrieve()
        {
            var dataStore = new DataStore("dw_clients", _dataContext);

            dataStore.Retrieve();

            return dataStore;
        }
        
        public IDataStore RetrieveOne(string id)
        {
            var dataStore = new DataStore("dw_clients", _dataContext);

            dataStore.Retrieve(id);

            return dataStore;
        }
 
The first one works fine and the http GET responds me with the list of all clients :
[{"no_Ste":"01","cd_Cl":"TESTREG","vil":null,"des_Cl":null},{"no_Ste":"01","cd_Cl":"BISTRO","vil":null,"des_Cl":"BISTRO DES TILLEULS"},{"no_Ste":"01","cd_Cl":"SLBLAN1","vil":null,"des_Cl":"Client SL blanchisserie 1"}...]
 
but the second one throw me the following error :
 
ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
Parameter name: arguments

PowerBuilder.Data.AdoDbDataSource<TModel>.Retrieve(object[] arguments)

I guess it's because the Retrieve(object[] arguments) doesn't like my string parameter as an ID, how can i make it works?

Best regards,

Olivier.

Accepted Answer
Olivier PAVLIN Accepted Answer Pending Moderation
  1. Wednesday, 13 November 2019 15:46 PM UTC
  2. SnapDevelop
  3. # Permalink

Thank you very much, im starting to think that my problem is coming from the fact that i have 2 KEY for that Dw_Clients object and that i should write a retrieve method taking two string as parameters like this:

        [HttpGet("{id1}/{id2}")]
        [ProducesResponseType(typeof(Dw_Clients), StatusCodes.Status200OK)]
        [ProducesResponseType(StatusCodes.Status404NotFound)]
        public ActionResult<Dw_Clients> RetrieveOne(string id1, string id2)
        {
            var client = _clientservice.RetrieveOne(id1, id2);

            if (client.RowCount == 0)
            {
                return NotFound();
            }

            return client.FirstOrDefault<Dw_Clients>();
        }

But i am still hiting the same error even though i am passing the 2 string ID in my httpget :

http://localhost:5000/api/client/RetrieveOne/01/TESTREG

I am joining the screenshot of my debug session just before i get the ArgumentOutOfRangeException...

 

Another thing is that in my table the ID fields No_Ste and Cd_Cl are declared as char[2] and char[7] as shown in my second screenshot, maybe the ArgumentOutOfRangeExceptioncomes from here...

 

Edit 13/11/19 18:11

My retrieval arguments in this datawindow is empty (as shown in capture4)

Attachments (3)
Comment
  1. Olivier PAVLIN
  2. Wednesday, 13 November 2019 21:16 PM UTC
Ok thank you very much.
  1. Helpful
  1. Olivier PAVLIN
  2. Thursday, 14 November 2019 08:10 AM UTC
Just to be clear that mean that i will have in my ASP.Net web api as many services as i have datawindows in my PB project.

The way i was seeing it is that i would have create one and only one big data model object dw_client that will have all the properties in my table, then depending on the need of each datawindow i would have called a different function in my service GetAllClient() or GetClientById(string id)...
  1. Helpful
  1. Armeen Mazda @Appeon
  2. Thursday, 14 November 2019 16:18 PM UTC
Thanks for sharing the solution!
  1. Helpful
There are no comments made yet.
Olivier PAVLIN Accepted Answer Pending Moderation
  1. Wednesday, 13 November 2019 13:24 PM UTC
  2. SnapDevelop
  3. # 1

Hi thank you for your reply, im not sure what you mean by "retrieval arguments defined for the DataWindow object", i am quite new to PB...

My RetreiveOne method in my controller to retreive a Dw_Clients object from my database is this one:

    // GET api/client/retrieveone/{id}
    [HttpGet("{id}")]
    [ProducesResponseType(typeof(Dw_Clients), StatusCodes.Status200OK)]
    [ProducesResponseType(StatusCodes.Status404NotFound)]
    public ActionResult<Dw_Clients> RetrieveOne(string id)
    {
          var client = _clientservice.RetrieveOne(id);

          if (client.RowCount == 0)
          {
              return NotFound();
          }

          return client.FirstOrDefault<Dw_Clients>();
     }

and is calling this function from my service class :

      public IDataStore RetrieveOne(string id)
      {
          var dataStore = new DataStore("dw_clients", _dataContext);

          dataStore.Retrieve(id);

          return dataStore;
      }

the error happen during dataStore.Retrieve(id) above as the stack below is showing:

ArgumentOutOfRangeException: Specified argument was out of the range of valid values. Parameter name: arguments

  • PowerBuilder.Data.AdoDbDataSource<TModel>.Retrieve(object[] arguments)

  • PowerBuilder.Data.DataStore<TModel>.Retrieve(object[] arguments)

  • WebApiSQLAnywhere.Services.ClientService.RetrieveOne(string id) in ClientService.cs

    1. dataStore.Retrieve(id);
  • WebApiSQLAnywhere.Controllers.ClientController.RetrieveOne(string id) in ClientController.cs

    1. var client = _clientservice.RetrieveOne(id);

 

Basically what i did is just the same as the "Create a Web API" tutorial, except that my database is a SQL Anywhere and the table i am getting data from is called "Clients" instead of "Departement" and my key to retreive one Client is a string value.

 

 

 

Comment
  1. Michael Kramer
  2. Wednesday, 13 November 2019 13:46 PM UTC
This to me looks like you pass a string as parameter but the DataWindow object receiving that string as argument expects a numeric value. Your web API accepts a string but your DataWindow object may be more restrictive.,

The tutorials for web API focus on the ASP.NET peculiarities and expects you are well versed in the realm of DataWindow objects and PowerScript coding.
  1. Helpful
  1. Michael Kramer
  2. Wednesday, 13 November 2019 15:21 PM UTC
Your C# code looks fine - at least for now. Your error tells me that the C# code actually sends a string value to the "DataStore" holding the "DataWindow object" which defines the SQL including the results and the SELECT arguments. I will make a small "click here; then there" description for you 0 but it will be in evening after office hours. Sorry.

Anyone else wants to join in on the discussion of retrieval argument for DataWindows? Feel free to join. Especially if you can help out Olivier before I have time.
  1. Helpful
There are no comments made yet.
Michael Kramer Accepted Answer Pending Moderation
  1. Wednesday, 13 November 2019 12:18 PM UTC
  2. SnapDevelop
  3. # 2

Hey Olivier,

You should have no issue using simple datatypes as retrieval arguments. "Simple" = numeric, string, date, time, datetime.

What are the retrieval arguments defined for the DataWindow object?

 

Comment
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.