Skip to content
This repository was archived by the owner on Feb 17, 2025. It is now read-only.

Commit 47298dc

Browse files
Ihar YakimushIhar Yakimush
authored andcommitted
move demo to another project
1 parent b79cf95 commit 47298dc

File tree

11 files changed

+643
-73
lines changed

11 files changed

+643
-73
lines changed

Community.Data.OData.Linq.sln

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio 15
4-
VisualStudioVersion = 15.0.27130.2024
4+
VisualStudioVersion = 15.0.27130.2027
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Community.OData.Linq", "Community.Data.OData.Linq\Community.OData.Linq.csproj", "{0EA4A9B7-BEE7-4500-8676-0B18E7B369D2}"
77
EndProject
@@ -14,6 +14,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
1414
README.md = README.md
1515
EndProjectSection
1616
EndProject
17+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Community.OData.Linq.Demo", "Community.OData.Linq.Demo\Community.OData.Linq.Demo.csproj", "{DE428072-2C49-4F4A-8F2E-DB976C0BC797}"
18+
EndProject
1719
Global
1820
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1921
CodeAnalysis|Any CPU = CodeAnalysis|Any CPU
@@ -33,6 +35,12 @@ Global
3335
{6B5E0D65-A1AE-4EB4-A496-B6588F03D373}.Debug|Any CPU.Build.0 = Debug|Any CPU
3436
{6B5E0D65-A1AE-4EB4-A496-B6588F03D373}.Release|Any CPU.ActiveCfg = Release|Any CPU
3537
{6B5E0D65-A1AE-4EB4-A496-B6588F03D373}.Release|Any CPU.Build.0 = Release|Any CPU
38+
{DE428072-2C49-4F4A-8F2E-DB976C0BC797}.CodeAnalysis|Any CPU.ActiveCfg = Debug|Any CPU
39+
{DE428072-2C49-4F4A-8F2E-DB976C0BC797}.CodeAnalysis|Any CPU.Build.0 = Debug|Any CPU
40+
{DE428072-2C49-4F4A-8F2E-DB976C0BC797}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
41+
{DE428072-2C49-4F4A-8F2E-DB976C0BC797}.Debug|Any CPU.Build.0 = Debug|Any CPU
42+
{DE428072-2C49-4F4A-8F2E-DB976C0BC797}.Release|Any CPU.ActiveCfg = Release|Any CPU
43+
{DE428072-2C49-4F4A-8F2E-DB976C0BC797}.Release|Any CPU.Build.0 = Release|Any CPU
3644
EndGlobalSection
3745
GlobalSection(SolutionProperties) = preSolution
3846
HideSolutionNode = FALSE

Community.Data.OData.Linq.xTests/ExpandTests.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,5 +112,20 @@ public void ExpandCollectionWithTopExceedLimit()
112112
Assert.Throws<ODataException>(
113113
() => ClassWithCollection.CreateQuery().OData().SelectExpand("Name", "Link2($top=101)"));
114114
}
115+
116+
[Fact]
117+
public void ExpandCollectionWithFilterAndSelect()
118+
{
119+
ISelectExpandWrapper[] result = ClassWithCollection.CreateQuery().OData().SelectExpand("Name", "Link2($filter=Id eq 311;$select=Name)").ToArray();
120+
121+
IDictionary<string, object> metadata = result[0].ToDictionary();
122+
123+
// Not expanded by default
124+
Assert.Equal(2, metadata.Count);
125+
IEnumerable<ISelectExpandWrapper> collection = metadata["Link2"] as IEnumerable<ISelectExpandWrapper>;
126+
Assert.Single(collection);
127+
128+
Assert.Equal(1, collection.Single().ToDictionary().Count);
129+
}
115130
}
116131
}

Community.Data.OData.Linq.xTests/Sample.cs

Lines changed: 0 additions & 53 deletions
This file was deleted.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>netcoreapp2.0</TargetFramework>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<ProjectReference Include="..\Community.Data.OData.Linq\Community.OData.Linq.csproj" />
10+
</ItemGroup>
11+
12+
</Project>
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
namespace Community.OData.Linq.Demo
2+
{
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
7+
public static class ExpandDemo
8+
{
9+
public static void SelectExpand1()
10+
{
11+
Console.WriteLine(nameof(SelectExpand1));
12+
Console.WriteLine("/*");
13+
14+
IQueryable<Sample> dataSet = Sample.CreateQuerable();
15+
ISelectExpandWrapper[] filterResult = dataSet.OData().SelectExpand(
16+
"Name",
17+
"RelatedEntity($select=Id),RelatedEntitiesCollection($filter=Id ge 200;$top=1)").ToArray();
18+
19+
/*
20+
|-Name: name1
21+
|-RelatedEntitiesCollection:
22+
|-RelatedEntity:
23+
| |-Id: 10
24+
| |---
25+
26+
|-Name: name2
27+
|-RelatedEntitiesCollection:
28+
| |-Id: 200
29+
| |-Name: name200
30+
| |---
31+
|-RelatedEntity:
32+
| |-Id: 20
33+
| |---
34+
35+
|-Name: name3
36+
|-RelatedEntitiesCollection:
37+
| |-Id: 300
38+
| |-Name: name300
39+
| |---
40+
|-RelatedEntity:
41+
| |-Id: 30
42+
| |---
43+
*/
44+
foreach (var sample in filterResult)
45+
{
46+
PrintRecursive(sample);
47+
}
48+
49+
Console.WriteLine("*/");
50+
Console.WriteLine(Environment.NewLine);
51+
}
52+
53+
public static void SelectExpand2()
54+
{
55+
Console.WriteLine(nameof(SelectExpand2));
56+
Console.WriteLine("/*");
57+
58+
IQueryable<Sample> dataSet = Sample.CreateQuerable();
59+
ISelectExpandWrapper[] filterResult = dataSet.OData().SelectExpand(
60+
"Id",
61+
"RelatedEntity,RelatedEntitiesCollection($top=2)").ToArray();
62+
63+
/*
64+
|-Id: 1
65+
|-RelatedEntitiesCollection:
66+
| |-Id: 100
67+
| |-Name: name100
68+
| |---
69+
| |-Id: 101
70+
| |-Name: name101
71+
| |---
72+
|-RelatedEntity:
73+
| |-Id: 10
74+
| |-Name: name10
75+
| |---
76+
77+
|-Id: 2
78+
|-RelatedEntitiesCollection:
79+
| |-Id: 200
80+
| |-Name: name200
81+
| |---
82+
| |-Id: 201
83+
| |-Name: name201
84+
| |---
85+
|-RelatedEntity:
86+
| |-Id: 20
87+
| |-Name: name20
88+
| |---
89+
90+
|-Id: 3
91+
|-RelatedEntitiesCollection:
92+
| |-Id: 300
93+
| |-Name: name300
94+
| |---
95+
| |-Id: 301
96+
| |-Name: name301
97+
| |---
98+
|-RelatedEntity:
99+
| |-Id: 30
100+
| |-Name: name30
101+
| |---
102+
*/
103+
foreach (var sample in filterResult)
104+
{
105+
PrintRecursive(sample);
106+
}
107+
108+
Console.WriteLine("*/");
109+
Console.WriteLine(Environment.NewLine);
110+
}
111+
112+
private static void PrintRecursive(ISelectExpandWrapper wrapper, string indent = "|")
113+
{
114+
var metadata = wrapper.ToDictionary();
115+
foreach (KeyValuePair<string, object> pair in metadata)
116+
{
117+
if (pair.Value is ISelectExpandWrapper property)
118+
{
119+
Console.WriteLine($"{indent}-{pair.Key}:");
120+
PrintRecursive(property, indent + " |");
121+
continue;
122+
}
123+
124+
if (pair.Value is IEnumerable<ISelectExpandWrapper> collection)
125+
{
126+
Console.WriteLine($"{indent}-{pair.Key}:");
127+
foreach (ISelectExpandWrapper item in collection)
128+
{
129+
PrintRecursive(item, indent + " |");
130+
}
131+
132+
continue;
133+
}
134+
135+
Console.WriteLine($"{indent}-{pair.Key}: {pair.Value}");
136+
}
137+
138+
if (indent == "|")
139+
{
140+
Console.WriteLine();
141+
}
142+
else
143+
{
144+
Console.WriteLine(indent + "---");
145+
}
146+
}
147+
}
148+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
namespace Community.OData.Linq.Demo
2+
{
3+
using System;
4+
using System.Linq;
5+
6+
public static class FilterDemo
7+
{
8+
public static void BySimpleProperties()
9+
{
10+
Console.WriteLine(nameof(BySimpleProperties));
11+
12+
IQueryable<Sample> dataSet = Sample.CreateQuerable();
13+
Sample[] filterResult = dataSet.OData().Filter("Id eq 2 or Name eq 'name3'").ToArray();
14+
15+
// Id:2 Name:name2
16+
// Id:3 Name:name3
17+
foreach (Sample sample in filterResult)
18+
{
19+
Console.WriteLine(string.Format("Id:{0} Name:{1}", sample.Id, sample.Name));
20+
}
21+
22+
Console.WriteLine(Environment.NewLine);
23+
}
24+
25+
public static void ByRelatedEntity()
26+
{
27+
Console.WriteLine(nameof(ByRelatedEntity));
28+
29+
IQueryable<Sample> dataSet = Sample.CreateQuerable();
30+
Sample[] filterResult = dataSet.OData().Filter("RelatedEntity/Id eq 10").ToArray();
31+
32+
// Id: 1 Name: name1
33+
foreach (Sample sample in filterResult)
34+
{
35+
Console.WriteLine(string.Format("Id:{0} Name:{1}", sample.Id, sample.Name));
36+
}
37+
38+
Console.WriteLine(Environment.NewLine);
39+
}
40+
}
41+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
namespace Community.OData.Linq.Demo
2+
{
3+
using System;
4+
using System.Linq;
5+
6+
public static class OrderByDemo
7+
{
8+
public static void BySimpleProperties()
9+
{
10+
Console.WriteLine(nameof(BySimpleProperties));
11+
12+
IQueryable<Sample> dataSet = Sample.CreateQuerable();
13+
Sample[] filterResult = dataSet.OData().OrderBy("Id desc").ToArray();
14+
15+
// Id:3 Name:name3
16+
// Id:2 Name:name2
17+
// Id:1 Name:name1
18+
foreach (Sample sample in filterResult)
19+
{
20+
Console.WriteLine("Id:{0} Name:{1}", sample.Id, sample.Name);
21+
}
22+
23+
Console.WriteLine(Environment.NewLine);
24+
}
25+
}
26+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
namespace Community.OData.Linq.Demo
2+
{
3+
class Program
4+
{
5+
static void Main(string[] args)
6+
{
7+
FilterDemo.BySimpleProperties();
8+
FilterDemo.ByRelatedEntity();
9+
OrderByDemo.BySimpleProperties();
10+
SelectDemo.OnlyNameField();
11+
12+
ExpandDemo.SelectExpand1();
13+
ExpandDemo.SelectExpand2();
14+
}
15+
}
16+
}

0 commit comments

Comments
 (0)