OData / AspNetCoreOData

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

Instance expression Expression.Default, Expression.Convert(Expression.Constant(null),typeof(DesiredObject)) fails during serialization #265

Open Truetotosse opened 2 years ago

Truetotosse commented 2 years ago

When Instance property in OData Container Class is patched from property to expression containing Expression.Default or Expression.Convert(Expression.Constant(null),typeof(DesiredObject)) serialization fails with the following error: the EDM instance of type [some-type] is missing the property [some-property] Doesnt work:

Container = new SingleExpandedProperty`1() {
Name = "Property", 
Value = new SelectAll`1() {
    Model = 
value(Microsoft.AspNetCore.OData.Query.Container.LinqParameterContainer+TypedLinqParameterContainer`1[Microsoft.OData.Edm.IEdmModel]).TypedProperty, 
    **Instance = IIF($it.Property.IsAllowed, $it.Property, default(PropertyClass)),** 
    UseInstanceForProperties = True}, 
IsNull = ($it.Property == null)}

Work:

Container = new SingleExpandedProperty`1() {
Name = "Property", 
Value = new SelectAll`1() {
    Model = 
value(Microsoft.AspNetCore.OData.Query.Container.LinqParameterContainer+TypedLinqParameterContainer`1[Microsoft.OData.Edm.IEdmModel]).TypedProperty, 
    **Instance = $it.Property,** 
    UseInstanceForProperties = True}, 
IsNull = ($it.Property == null)}

In the first example serialization fails only in the Default(PropertyClass) case

Sreejithpin commented 2 years ago

Can you please provide us class definition, error details, call stack etc. Will be great if you can give a repro as well