AspNetCoreOData
AspNetCoreOData copied to clipboard
Function.Returns<> non primitive type error
Microsoft.AspNetCore.OData v8.0.8
In my EDM model I have a function declared in this way:
function = builder.Function("MyFunction");
function.Parameter<int>("customId");
function.Returns<MyTypedClass>();
If I call the function, the server response will be:
{
If I change the Returns to ReturnsCollection:
function = builder.Function("MyFunction");
function.Parameter<int>("customId");
function.ReturnsCollection<MyTypedClass>();
works correctly, but I need to return an array of 1 element. It's not necessary.
If I call the function, the server response will be:
{
If this is all you get in the response, it appears that some serialization exception is happening that is stopping the response from being written.
Can you check console logs on the application to see if something OData serialization is present there?
This same issue (partial output payload) happened to me once and I was able to solve the problem after inspecting the exception on the logs.
@julealgon console output contains only this messages:
'Microsoft.OData.ODataException' in System.Private.CoreLib.dll
Consider that I'm serializing exactly the same object, but if I return it as a Collection it works, otherwise not. I think that if it is a serialization issue must be present in both cases (Returns<> and ReturnsCollection<>). Tell me if I can share more details about the error.
@mferraricloudsurfers do you think you could provide a minimal repro sample app for this?
Here the example; there are 2 endpoints (TestFunctionKO and TestFunctionOK), the KO one is not working correctly.
Tried the project just now. It is not exactly clear how the project reproduces the problem in the OP though. It has 2 classes, TestClass and TestClass2. The former is detected as an entity (due to the builder.EntityType<TestClass>().HasKey(t => t.TestId); call), while the latter is detected as a complextype.
If you add
builder.EntityType<TestClass2>().HasKey(t => t.TestId);
to the EDM builder, then both behave the same.
IIRC, if you are returning an entity, you have to tell this explicitly in the function EDM and you also probably should add a dataset for that type (don't quote me on that).
The fact that there are no exceptions/warnings anywhere is weird though, I can give you that. The OData team should probably fix that part.