OData / AspNetCoreOData

ASP.NET Core OData: A server library built upon ODataLib and ASP.NET Core
Other
457 stars 157 forks source link

Could not find a property named 'keyName' on type 'MyClass' #1251

Closed abhinavkumarverma-gmail closed 4 months ago

abhinavkumarverma-gmail commented 4 months ago

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

  1. Create a class, c# WebApi as show below:
  2. Call the API with URL as "https://localhost:8080/api/requests?$format=json&$top=10&$orderby=keyName&$count=true"
  3. 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

xuzhg commented 4 months ago

@abhinavkumarverma-gmail Thanks for reporting this. I think it's related to the case insensitive configuration (by default) for non-EdmModel scenario. See details at: https://github.com/OData/AspNetCoreOData/issues/1190#issuecomment-1986299357.

And It should be fixed in the latest nightly package but haven't released at nuget.org. For nightly, please check the readme of this repository.

abhinavkumarverma-gmail commented 4 months ago

Thanks for the reply.

jholovacs commented 1 month ago

How is this considered completed and closed when there is no 8.2.* version above 8.2.4 where this is fixed? This is a breaking change that actually caused an outage in our product. These shouldn't be closed until there's an available remediation.