OData v4.0 introduced the open type concept in order to manage dynamic properties in the payload without defining them in the EDM model.
Requirements:
- Microsoft ASP.NET WebAPI 2.2 for OData v4.0 5.8.0
- JayData 1.5.0 CTP
- Olingo OData Client for JavaScript Library 4.0.0
Define custom OData v4 open type – .NET server-side
public class TestItemGuid { public TestItemGuid() { openProperties = new Dictionary(); } ... public IDictionary openProperties { get; set; } ... }
Define custom open type in JayData – JavaScript
$data.Entity.extend('JayData.Test.CommonItems.Entities.TestItemGuid', {...}, { openType: { value: true } })
If you not define your property at client side it JayData use defaults. Default OpenType property is ‘dynamicProperties’.
Defining custom dynamic properties in JayData
$data.Entity.extend('JayData.Test.CommonItems.Entities.TestItemGuid', { ... openProperties: { type: $data.Object } ... }, { openType: { value: 'openProperties' } })
Setting fields of open types – .NET server-side
var item1 = new TestItemGuid { Id = Guid.NewGuid() }; item1.openProperties.Add("t0", 1.0f); item1.openProperties.Add("t1", false); item1.openProperties.Add("t2", DateTime.Now);
Setting values to properties of open types with JayData – JavaScript
item.openProperties.t1 = true;