This repository was archived by the owner on Feb 17, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
5. Select and Expand to JSON
IharYakimush edited this page Mar 1, 2018
·
1 revision
using System;
using System.Linq;
using Community.OData.Linq;
using Community.OData.Linq.Json;
using Newtonsoft.Json;
Select only Name, expand Id from RelatedEntity and top 1 from RelatedEntitiesCollection where Id greater than 200
IQueryable<Sample> dataSet = Sample.CreateQuerable();
var result = dataSet.OData().SelectExpandJsonToken(
"Name",
"RelatedEntity($select=Id),RelatedEntitiesCollection($filter=Id ge 200;$top=1)");
Console.WriteLine(result.ToString(Formatting.Indented));
[
{
"Name": "name1",
"RelatedEntitiesCollection": [],
"RelatedEntity": {
"Id": 10
}
},
{
"Name": "name2",
"RelatedEntitiesCollection": [
{
"Id": 200,
"Name": "name200"
}
],
"RelatedEntity": {
"Id": 20
}
},
{
"Name": "name3",
"RelatedEntitiesCollection": [
{
"Id": 300,
"Name": "name300"
}
],
"RelatedEntity": {
"Id": 30
}
}
]