C # WebAPI not arranging dynamic properties correctly

I am creating a new C # OData4 web API with a class with a name Callthat has dynamic properties that OData 4 resolves through "Open Types". I believe that I set everything up and set it right, but the serialized answer does not include dynamic properties.

Am I misconfigured something wrong?

public partial class Call 
{
    public int Id { get; set; }
    public string Email { get; set; }
    public IDictionary<string, object> DynamicProperties { get; }
}

public class CallController : ODataController
{
    [EnableQuery]
    public IQueryable<Call> GetCall([FromODataUri] int key)
    {
        return _context.Call.GetAll();
    }
}

public static partial class WebApiConfig
{
    public static void Register(HttpConfiguration config)
    {
        AllowUriOperations(config);

        ODataModelBuilder builder = new ODataConventionModelBuilder();
        builder.ComplexType<Call>();
        var model = builder.GetEdmModel();

        config.MapODataServiceRoute(RoutePrefix.OData4, RoutePrefix.OData4, model);    
    }

    private static void AllowUriOperations(HttpConfiguration config)
    {
        config.Count();
        config.Filter();
        config.OrderBy();
        config.Expand();
        config.Select();
    }
}
+5
source share
4 answers

If the value is in a key pair null, the property simply does not serialize. I expected it to be serialized for

"key": null

Here are some additional examples.

DynamicProperties.Add("somekey", 1);

"somekey": 1


DynamicProperties.Add("somekey", "1");

"somekey": "1"


DynamicProperties.Add("somekey", null);

0

OData, ( WebApiConfig.cs Register ( HttpConfiguration))

    config.Properties.AddOrUpdate("System.Web.OData.NullDynamicPropertyKey", val=>true, (oldVal,newVal)=>true);

.

+1

, Call OpenType="true"? , EntitySet, :

builder.ComplexType<Call>();

builder.EntitySet<Call>("Calls");

OpenType="true" , , DynamicProperties

0

configuration.SetSerializeNullDynamicProperty(true); , .

0

Source: https://habr.com/ru/post/1666561/


All Articles