Could not find a property named 'keyName' on type 'MyClass' on ASP.NET Core OData 8.2.5 #1252
Unanswered
abhinavkumarverma-gmail
asked this question in
General
Replies: 1 comment 2 replies
-
Could you please provide the response received when the $orderby parameter is not provided? |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Assemblies affected
ASP.NET Core OData 8.2.5
Describe the bug
I am getting error - Could not find a property named 'keyName' on type 'MyClass' on ASP.NET Core OData 8.2.5, but it is working fine till ASP.NET Core OData 8.2.4 version.
The exception is raised at line "(int)oDataQueryOptions.Count?.GetEntityCount(oDataQueryOptions.Filter?.ApplyTo(myClassQuery, new ODataQuerySettings()) ?? myClassQuery)" mentioned in below code snippet
Reproduce steps
Create a class, c# WebApi as show below:
Call the API with URL as "https://localhost:8080/api/requests?$format=json&$top=10&$orderby=keyName&$count=true"
It will give an exception.
Model
Public class MyClass
{
[Key]
public int AutoId {get;set;}
public string KeyName {get;set;}
public string Description {get;set;}
}
WebAPI
public Task GetMyClassData(ODataQueryOptions oDataQueryOptions)
{
var myClassQuery = dbContext.Table1
.Select(t => new MyClass
{
AutoId = t.Autoid,
KeyName = t.KeyName,
Description = t.Description,
});
var response = new
{
totalRecords = (int)oDataQueryOptions.Count?.GetEntityCount(oDataQueryOptions.Filter?.ApplyTo(myClassQuery, new ODataQuerySettings()) ?? myClassQuery),
records = oDataQueryOptions.ApplyTo(myClassQuery).Cast()
};
}
Request/Response
Request: https://localhost:8080/api/requests?$format=json&$top=10&$orderby=keyName&$count=true)
Response: Could not find a property named 'keyName' on type 'MyClass'
Expected behavior
It should return valid object
Beta Was this translation helpful? Give feedback.
All reactions