Open aetos382 opened 1 year ago
It seems like record
s is just a special case, but this problem is much wider.
Does it work if you provide this Order
implementation?
public class Product
{
public Product(string id, string name)
{
this.Id = id;
this.Name = name;
}
public string Id { get; }
public string Name { get; }
}
If it produces the same error (which I assume it will), I'd suggest renaming your issue to talk about "types without default constructor" instead of limiting it to "records".
This would basically be a duplicate of:
Surely the essential reason is that the payload type has no parameterless constructor. But records are specifically supported in ASP.NET Core WebAPI. I think there should be no difference in that limitation between using regular WebAPI and using OData. So what is available in the standard WebAPI should be available in OData as well.
If ASP.NET OData has plans to go beyond the scope of standard WebAPI support and fully support bindings to types that have no parameterless constructors, that would be great. However, if it will be a long time before that release, I would like to see support for records as a special case for now.
Assemblies affected ASP.NET Core OData 8.2
Describe the bug Does not support record as request payload type.
Reproduce steps Clone this repo and run the app. https://github.com/aetos382/RecordSupport
Data Model
EDM (CSDL) Model
Request/Response
Expected behavior All request payloads are successfully deserialized and passed as arguments to the controller's action method.
Actual behavior The request for
Products
succeeds. This controller does not use any OData functionality. ForOrders
, the action method is called, but the argument is always passednull
. ForCustomers
, no action methods are called.Additional context Requests to
Orders
andCustomers
seem to raise the following exceptions.