We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

OData V4 not found with key string

Hi,
I'm using string as primarykey but OData V4 adaptor call method with http://url/ODataService/Entity(key) instead of ('key').

How can I change it or use another OData Url Key Delimiter (ex. http://url/ODataService/Entity/key)?

Thanks
Emanuele

11 Replies

PO Prince Oliver Syncfusion Team January 9, 2017 11:49 AM UTC

Hi Emanuele,   
  
Thanks for contacting Syncfusion Support.   
  
We were unable to understand your query. Please explain your scenario where you need to use primary key as string and share additional details with sample or screenshot.   
  
If you are looking to change the odata query string based on your service URL, you can use querying to alter the URL.   
  
Refer to the following JS UG link for more information:   
  
JS Playground sample demonstrating Odata v4:   
  
MVC sample link:   
  
Regards,   
Prince   



EF Emanuele Filardo January 9, 2017 12:19 PM UTC

I'll try to explain better.
I'm using RESTier as OData backend and there aren't problem to fetch the list of entities and the url is https://myappurl/api/ODataService/Customers;
When I update an entity, the DataManager use this url https://myappurl/api/ODataService/Customers(keyvalue) and receive Not Found, because it expect this url https://myappurl/api/ODataService/Customers('keyvalue') or https://myappurl/api/ODataService/Customer/keyvalue

I need to add apostrophe inside parentheses or use slashes, is possible?


PO Prince Oliver Syncfusion Team January 10, 2017 02:26 PM UTC

Hi Emanuele, 

Thanks for your update. 

In order to modify the query string based on your requirement. You can use custom adaptor in datamanager to extend OData adaptor and modify the convertToQueryString method. Have a look at the following code snippet. 

<script type="text/javascript"> 
     $(function () { 
          var dataManager = ej.DataManager({ url: "http://services.odata.org/V4/Northwind/Northwind.svc/", crossDomain: true, adaptor: new customAdaptor() }); 
          var query = new ej.Query().from("Orders").select("OrderID", "CustomerID", "EmployeeID").take(5); 
          var promise = dataManager.executeQuery(query); 
          promise.done(function (e) { 
              $("#table1 tbody").html($("#tableTemplate").render(e.result.value)); 
          }); 
      }); 
         // extending ODataAdaptor as custom adaptor to alter query creation based on our requirement 
          var customAdaptor = new ej.ODataAdaptor().extend({ 
 
 
                             convertToQueryString: function (req, query, dm) { 
                                    var res = [], tableName = req.table || ""; 
                                    delete req.table; 
 
                                    if (dm.dataSource.requiresFormat) 
                                           req["$format"] = "json"; 
 
                                    for (var prop in req) 
                                           res.push(prop + "=" + req[prop]); 
 
                                    res = res.join("&"); 
 
                                    if (dm.dataSource.url && dm.dataSource.url.indexOf("?") !== -1 && !tableName) 
                                           return res; 
 
                                    return res.length ? tableName + "/?" + res : tableName || "";// add "/" or enclose the query string in '' single quotes 
                             }, 
 
          }); 
    </script> 

We have attached a sample for your convenience, refer to the following link for the sample: 

Regards, 
Prince 



EF Emanuele Filardo January 11, 2017 05:17 PM UTC

Is possible to create customAdaptor with c# instead of js?


PO Prince Oliver Syncfusion Team January 12, 2017 09:15 AM UTC

Hi Emanuele, 

Thank you for contacting Syncfusion support. 

Currently we cannot create custom adaptor in C# to modify the query string as per your requirement. 

Refer to the following KB link for server side Datamanager operations: https://www.syncfusion.com/kb/4300/server-side-api-for-datamanager-operations 

Refer to the following UG link for MVC Datamanager: https://help.syncfusion.com/aspnetmvc/datamanager/data-adaptors 

Regards, 
Prince 



AB Alberto Barrera March 23, 2018 02:26 AM UTC

Any solution to set ('string') not (int)?


IB Ilakkiya Baskar Syncfusion Team March 23, 2018 10:51 AM UTC

Hi Emanuele, 
Sorry for the inconvenience . 
We have validated your scenario and confirmed “key as string” as a defect. We will fix this issue and include in our upcoming Volume 1 SP1 ,2018 release which will be rolled out by the end of this month. 
Regards, 
Keerthana.  



BF Borja Fernández August 8, 2018 05:15 PM UTC

Hello,

I'm having the same issue in Asp.Net core, is there any solution?

Regards,
Borja Fernández.


KV Karthikeyan Viswanathan Syncfusion Team August 9, 2018 05:01 PM UTC

Hi Borja, 
 
The “key as string” issue fix is available from 2018 volume 2 release. So, we are suggested to use the latest version of ASP.Net Core. 


Still, If you have an issue related to “key”. Please share the below details: 

  1. Share the code snippet which it is help to reproduce this issue.
  2. Share the issue reproducing sample if possible.
  3. Share the screenshot of this issue if any error occur.
  4. Share the product version details.
 
Regards, 
Karthikeyan V. 



BF Borja Fernández August 10, 2018 03:37 PM UTC

Sorry, forget to say I was using ej2. 

Best regards


KV Karthikeyan Viswanathan Syncfusion Team August 14, 2018 09:00 AM UTC

Hi Borja,  
We have checked and confirmed “With string value as primary key ‘not found’ error thrown in OdataV4Adaptor update Request” as a defect. This fix will be included in any of our upcoming patch releases.  
Until then we appreciate your patience.  
Regards,  
Karthikeyan V. 


Loader.
Up arrow icon