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

Commit c4c3aa0

Browse files
authored
Merge pull request #39 from IharYakimush/develop
init performance, async support
2 parents 394bbc0 + 2ecc45d commit c4c3aa0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1211
-287
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,3 +286,4 @@ __pycache__/
286286
*.btm.cs
287287
*.odx.cs
288288
*.xsd.cs
289+
/nupkg

Benchmark/Benchmark.csproj

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net6.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<PackageReference Include="BenchmarkDotNet" Version="0.13.1" />
12+
</ItemGroup>
13+
14+
<ItemGroup>
15+
<ProjectReference Include="..\Community.Data.OData.Linq.xTests\Community.OData.Linq.xTests.csproj" />
16+
</ItemGroup>
17+
18+
</Project>

Benchmark/InitQuery.cs

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
using BenchmarkDotNet.Attributes;
2+
3+
using Community.OData.Linq;
4+
using Community.OData.Linq.Builder;
5+
using Community.OData.Linq.OData.Query;
6+
using Community.OData.Linq.OData.Query.Expressions;
7+
using Community.OData.Linq.xTests.SampleData;
8+
9+
using Microsoft.Extensions.DependencyInjection;
10+
using Microsoft.OData;
11+
using Microsoft.OData.Edm;
12+
using Microsoft.OData.UriParser;
13+
14+
using System;
15+
using System.Collections.Generic;
16+
using System.ComponentModel.Design;
17+
using System.Linq;
18+
19+
namespace Benchmark
20+
{
21+
public class InitQuery
22+
{
23+
private static readonly ODataSimplifiedOptions SimplifiedOptions = new ODataSimplifiedOptions();
24+
25+
private static ODataUriResolver DefaultResolver = new StringAsEnumResolver { EnableCaseInsensitive = true };
26+
27+
private static readonly IEdmModel defaultEdmModel;
28+
29+
private static readonly IQueryable<ClassWithDeepNavigation> query;
30+
31+
static InitQuery()
32+
{
33+
query = ClassWithDeepNavigation.CreateQuery();
34+
35+
ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
36+
builder.AddEntityType(typeof(ClassWithDeepNavigation));
37+
builder.AddEntitySet(typeof(ClassWithDeepNavigation).Name, new EntityTypeConfiguration(new ODataModelBuilder(), typeof(ClassWithDeepNavigation)));
38+
defaultEdmModel = builder.GetEdmModel();
39+
}
40+
41+
[Benchmark]
42+
public Tuple<IQueryable, ServiceContainer> LegacyEdmAndContainer()
43+
{
44+
ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
45+
builder.AddEntityType(typeof(ClassWithDeepNavigation));
46+
builder.AddEntitySet(typeof(ClassWithDeepNavigation).Name, new EntityTypeConfiguration(new ODataModelBuilder(), typeof(ClassWithDeepNavigation)));
47+
var edmModel = builder.GetEdmModel();
48+
49+
ODataSettings settings = new ODataSettings();
50+
51+
ServiceContainer container = new ServiceContainer();
52+
container.AddService(typeof(IEdmModel), edmModel);
53+
container.AddService(typeof(ODataQuerySettings), settings.QuerySettings);
54+
container.AddService(typeof(ODataUriParserSettings), settings.ParserSettings);
55+
container.AddService(typeof(FilterBinder), new FilterBinder(container));
56+
container.AddService(typeof(ODataUriResolver), settings.Resolver ?? DefaultResolver);
57+
container.AddService(typeof(ODataSimplifiedOptions), SimplifiedOptions);
58+
container.AddService(typeof(ODataSettings), settings);
59+
container.AddService(typeof(DefaultQuerySettings), settings.DefaultQuerySettings);
60+
container.AddService(typeof(SelectExpandQueryValidator), new SelectExpandQueryValidator(settings.DefaultQuerySettings));
61+
62+
return new Tuple<IQueryable, ServiceContainer>(query, container);
63+
}
64+
65+
[Benchmark]
66+
public Tuple<IQueryable, IServiceProvider> LegacyContainer()
67+
{
68+
var edmModel = defaultEdmModel;
69+
70+
if (edmModel.SchemaElements.Count(e => e.SchemaElementKind == EdmSchemaElementKind.EntityContainer) == 0)
71+
{
72+
throw new ArgumentException("Provided Entity Model have no IEdmEntityContainer", nameof(edmModel));
73+
}
74+
75+
ODataSettings settings = new ODataSettings();
76+
77+
ServiceContainer container = new ServiceContainer();
78+
container.AddService(typeof(IEdmModel), edmModel);
79+
container.AddService(typeof(ODataQuerySettings), settings.QuerySettings);
80+
container.AddService(typeof(ODataUriParserSettings), settings.ParserSettings);
81+
container.AddService(typeof(FilterBinder), new FilterBinder(container));
82+
container.AddService(typeof(ODataUriResolver), settings.Resolver ?? DefaultResolver);
83+
container.AddService(typeof(ODataSimplifiedOptions), SimplifiedOptions);
84+
container.AddService(typeof(ODataSettings), settings);
85+
container.AddService(typeof(DefaultQuerySettings), settings.DefaultQuerySettings);
86+
container.AddService(typeof(SelectExpandQueryValidator), new SelectExpandQueryValidator(settings.DefaultQuerySettings));
87+
88+
return new Tuple<IQueryable, IServiceProvider>(query, container);
89+
}
90+
91+
[Benchmark]
92+
public Tuple<IQueryable, IServiceProvider> ODataExtension()
93+
{
94+
return new Tuple<IQueryable, IServiceProvider>(query.OData(), new ServiceContainer());
95+
}
96+
}
97+
}

Benchmark/Program.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// See https://aka.ms/new-console-template for more information
2+
using Benchmark;
3+
4+
using BenchmarkDotNet.Reports;
5+
using BenchmarkDotNet.Running;
6+
7+
Summary summary = BenchmarkRunner.Run<InitQuery>();
8+
9+
Console.WriteLine(summary);
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net6.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
7+
<IsPackable>false</IsPackable>
8+
9+
<UserSecretsId>d0588d8d-a4f1-422d-923f-5105da7e79a8</UserSecretsId>
10+
</PropertyGroup>
11+
12+
<ItemGroup>
13+
<PackageReference Include="Microsoft.Azure.Cosmos" Version="3.23.0" />
14+
<PackageReference Include="Microsoft.Extensions.Configuration" Version="6.0.0" />
15+
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="6.0.0" />
16+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
17+
<PackageReference Include="xunit" Version="2.4.1" />
18+
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
19+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
20+
<PrivateAssets>all</PrivateAssets>
21+
</PackageReference>
22+
<PackageReference Include="coverlet.collector" Version="3.1.0">
23+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
24+
<PrivateAssets>all</PrivateAssets>
25+
</PackageReference>
26+
</ItemGroup>
27+
28+
<ItemGroup>
29+
<ProjectReference Include="..\Community.Data.OData.Linq\Community.OData.Linq.csproj" />
30+
</ItemGroup>
31+
32+
</Project>
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace Comminuty.OData.CosmosDbTests.Models
8+
{
9+
public class TestEntity
10+
{
11+
public static TestEntity Create()
12+
{
13+
return new TestEntity() {
14+
Id = Guid.NewGuid().ToString(),
15+
Number = 1,
16+
Pk = "qwe",
17+
Item = TestEntity3.Create(),
18+
Childs = new[] { TestEntity2.Create(), TestEntity2.Create(), TestEntity2.Create(), TestEntity2.Create(), TestEntity2.Create() }
19+
};
20+
}
21+
22+
public string Id { get; set; }
23+
public string Pk { get; set; }
24+
25+
public int Number { get; set; }
26+
27+
public ICollection<TestEntity2> Childs { get; set;}
28+
29+
public TestEntity3 Item { get; set; }
30+
}
31+
32+
public class TestEntity2
33+
{
34+
public static TestEntity2 Create()
35+
{
36+
return new TestEntity2()
37+
{
38+
Id = Guid.NewGuid().ToString(),
39+
Number = 2,
40+
Pk = "qwe",
41+
Item = TestEntity3.Create()
42+
};
43+
}
44+
45+
public string Id { get; set; }
46+
public string Pk { get; set; }
47+
48+
public int Number { get; set; }
49+
50+
public TestEntity3 Item { get; set; }
51+
}
52+
53+
public class TestEntity3
54+
{
55+
public static TestEntity3 Create()
56+
{
57+
return new TestEntity3()
58+
{
59+
Id = Guid.NewGuid().ToString(),
60+
Number = 3,
61+
Pk = "qwe"
62+
};
63+
}
64+
65+
public string Id { get; set; }
66+
public string Pk { get; set; }
67+
68+
public int Number { get; set; }
69+
}
70+
}

0 commit comments

Comments
 (0)