Quantcast
Channel: JayData
Viewing all articles
Browse latest Browse all 11

Fullstack OData 4.0 howto–Open types

$
0
0

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:

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;


Viewing all articles
Browse latest Browse all 11

Latest Images

Trending Articles



Latest Images