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

Commit 803fef8

Browse files
author
IharYakimush
authored
Merge pull request #12 from IharYakimush/develop
release 1.2
2 parents fb01ba7 + dad1d89 commit 803fef8

28 files changed

+1018
-22
lines changed

Community.Data.OData.Linq.sln

Lines changed: 13 additions & 3 deletions
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.2027
4+
VisualStudioVersion = 15.0.27130.2024
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
@@ -10,13 +10,17 @@ EndProject
1010
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{9CBF15A2-B552-47EB-B2A1-475E4B05A4CA}"
1111
ProjectSection(SolutionItems) = preProject
1212
build.ps1 = build.ps1
13+
docker-compose.yml = docker-compose.yml
1314
LICENSE = LICENSE
15+
localEnv.ps1 = localEnv.ps1
1416
README.md = README.md
1517
EndProjectSection
1618
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}"
19+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Community.OData.Linq.Demo", "Community.OData.Linq.Demo\Community.OData.Linq.Demo.csproj", "{DE428072-2C49-4F4A-8F2E-DB976C0BC797}"
1820
EndProject
19-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Community.OData.Linq.Json", "Community.OData.Linq.Json\Community.OData.Linq.Json.csproj", "{6C454F01-28D1-49B1-BE98-244E5DA2D095}"
21+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Community.OData.Linq.Json", "Community.OData.Linq.Json\Community.OData.Linq.Json.csproj", "{6C454F01-28D1-49B1-BE98-244E5DA2D095}"
22+
EndProject
23+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Community.OData.Linq.EF6Tests", "Community.OData.Linq.EF6Tests\Community.OData.Linq.EF6Tests.csproj", "{F034D1D8-D44A-4B0E-96C4-855F30B239BA}"
2024
EndProject
2125
Global
2226
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -49,6 +53,12 @@ Global
4953
{6C454F01-28D1-49B1-BE98-244E5DA2D095}.Debug|Any CPU.Build.0 = Debug|Any CPU
5054
{6C454F01-28D1-49B1-BE98-244E5DA2D095}.Release|Any CPU.ActiveCfg = Release|Any CPU
5155
{6C454F01-28D1-49B1-BE98-244E5DA2D095}.Release|Any CPU.Build.0 = Release|Any CPU
56+
{F034D1D8-D44A-4B0E-96C4-855F30B239BA}.CodeAnalysis|Any CPU.ActiveCfg = Debug|Any CPU
57+
{F034D1D8-D44A-4B0E-96C4-855F30B239BA}.CodeAnalysis|Any CPU.Build.0 = Debug|Any CPU
58+
{F034D1D8-D44A-4B0E-96C4-855F30B239BA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
59+
{F034D1D8-D44A-4B0E-96C4-855F30B239BA}.Debug|Any CPU.Build.0 = Debug|Any CPU
60+
{F034D1D8-D44A-4B0E-96C4-855F30B239BA}.Release|Any CPU.ActiveCfg = Release|Any CPU
61+
{F034D1D8-D44A-4B0E-96C4-855F30B239BA}.Release|Any CPU.Build.0 = Release|Any CPU
5262
EndGlobalSection
5363
GlobalSection(SolutionProperties) = preSolution
5464
HideSolutionNode = FALSE
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+

2+
namespace Community.OData.Linq.xTests
3+
{
4+
using Community.OData.Linq.xTests.SampleData;
5+
using System;
6+
using System.Collections.Generic;
7+
using System.Linq;
8+
using System.Text;
9+
using Xunit;
10+
using Community.OData.Linq.Json;
11+
12+
public class OpenTypesTests
13+
{
14+
// Dynamic properties dictionary is null for one item
15+
16+
[Fact]
17+
public void FilterDefault()
18+
{
19+
Assert.Throws<NullReferenceException>(() => OpenType.CreateQuery().OData().Filter("Name1 eq 'n1'").ToArray());
20+
}
21+
22+
[Fact]
23+
public void FilterNullPropagationTrue()
24+
{
25+
var result = OpenType.CreateQuery().OData(c => c.QuerySettings.HandleNullPropagation = OData.Query.HandleNullPropagationOption.True).Filter("Name1 eq 'n1'").ToArray();
26+
27+
Assert.Single(result);
28+
}
29+
30+
[Fact]
31+
public void FilterNullPropagationFalse()
32+
{
33+
Assert.Throws<NullReferenceException>(() => OpenType.CreateQuery().OData(c => c.QuerySettings.HandleNullPropagation = OData.Query.HandleNullPropagationOption.False).Filter("Name1 eq 'n1'").ToArray());
34+
}
35+
36+
// Dynamic properties dictionary is not null, however properties with different names
37+
38+
[Fact]
39+
public void FilterDefaultWithNotNullDictionary()
40+
{
41+
var result = OpenType.CreateQueryWithNotNullDictionary().OData().Filter("Name1 eq 'n1'").ToArray();
42+
43+
Assert.Single(result);
44+
}
45+
46+
[Fact]
47+
public void FilterNullPropagationTrueWithNotNullDictionary()
48+
{
49+
var result = OpenType.CreateQueryWithNotNullDictionary().OData(c => c.QuerySettings.HandleNullPropagation = OData.Query.HandleNullPropagationOption.True).Filter("Name1 eq 'n1'").ToArray();
50+
51+
Assert.Single(result);
52+
}
53+
54+
[Fact]
55+
public void FilterNullPropagationFalseWithNotNullDictionary()
56+
{
57+
var result = OpenType.CreateQueryWithNotNullDictionary().OData(c => c.QuerySettings.HandleNullPropagation = OData.Query.HandleNullPropagationOption.False).Filter("Name1 eq 'n1'").ToArray();
58+
59+
Assert.Single(result);
60+
}
61+
62+
[Fact]
63+
public void FilterNullPropagationFalseWithNotNullDictionaryPropertyNotExists()
64+
{
65+
var result = OpenType.CreateQueryWithNotNullDictionary().OData(c => c.QuerySettings.HandleNullPropagation = OData.Query.HandleNullPropagationOption.False).Filter("Name3 eq 'n1'").ToArray();
66+
67+
Assert.Empty(result);
68+
}
69+
70+
// Dynamic properties dictionary is not null, all properties with same name
71+
72+
[Fact]
73+
public void FilterDefaultAllProperties()
74+
{
75+
var result = OpenType.CreateQueryWithAllProperties().OData().Filter("Name1 eq 'n1'").ToArray();
76+
77+
Assert.Single(result);
78+
}
79+
80+
[Fact]
81+
public void FilterNullPropagationTrueAllProperties()
82+
{
83+
var result = OpenType.CreateQueryWithAllProperties().OData(c => c.QuerySettings.HandleNullPropagation = OData.Query.HandleNullPropagationOption.True).Filter("Name1 eq 'n1'").ToArray();
84+
85+
Assert.Single(result);
86+
}
87+
88+
[Fact]
89+
public void FilterNullPropagationFalseAllProperties()
90+
{
91+
var result = OpenType.CreateQueryWithAllProperties().OData(c => c.QuerySettings.HandleNullPropagation = OData.Query.HandleNullPropagationOption.False).Filter("Name1 eq 'n1'").ToArray();
92+
93+
Assert.Single(result);
94+
}
95+
96+
[Fact]
97+
public void FilterNullPropagationFalseAllPropertiesNotExistingProperty()
98+
{
99+
var result = OpenType.CreateQueryWithAllProperties().OData(c => c.QuerySettings.HandleNullPropagation = OData.Query.HandleNullPropagationOption.False).Filter("Name3 eq 'n3'").ToArray();
100+
101+
Assert.Empty(result);
102+
}
103+
104+
//[Fact]
105+
//public void SelectDefaultWithNotNullDictionary()
106+
//{
107+
// var result = OpenType.CreateQueryWithNotNullDictionary().OData().Filter("Name1 eq 'n1'").SelectExpand("Name1").Single();
108+
109+
// var metadata = result.ToDictionary();
110+
111+
// Assert.Single(metadata);
112+
113+
// Assert.Equal("DynamicProperties", metadata.Single().Key);
114+
// Assert.Equal("Name1", (metadata.Single().Value as IDictionary<string, Object>).Single().Key);
115+
// Assert.Equal("n1", (metadata.Single().Value as IDictionary<string,Object>).Single().Value);
116+
//}
117+
118+
//[Fact]
119+
//public void SelectJsonDefaultWithNotNullDictionary()
120+
//{
121+
// var result = OpenType.CreateQueryWithNotNullDictionary().OData().SelectExpandJsonToken("Name1");
122+
123+
// Assert.Equal("{Nmae1:n1}", result.ToString());
124+
//}
125+
}
126+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
6+
namespace Community.OData.Linq.xTests.SampleData
7+
{
8+
public class OpenType
9+
{
10+
public int Id { get; set; }
11+
12+
public IDictionary<string, object> DynamicProperties { get; set; }
13+
14+
private static readonly OpenType[] items = new[]
15+
{
16+
new OpenType {Id = 1, DynamicProperties = new Dictionary<string,object>(){ {"Name1","n1" } } },
17+
new OpenType {Id = 2, DynamicProperties = new Dictionary<string,object>(){ {"Name2","n2" } } },
18+
new OpenType {Id = 3},
19+
};
20+
21+
private static readonly OpenType[] itemsWithNotNullDictionary = new[]
22+
{
23+
new OpenType {Id = 1, DynamicProperties = new Dictionary<string,object>(){ {"Name1","n1" } } },
24+
new OpenType {Id = 2, DynamicProperties = new Dictionary<string,object>(){ {"Name2","n2" } } },
25+
};
26+
27+
private static readonly OpenType[] itemsWithAllProperties = new[]
28+
{
29+
new OpenType {Id = 1, DynamicProperties = new Dictionary<string,object>(){ {"Name1","n1" } } },
30+
new OpenType {Id = 2, DynamicProperties = new Dictionary<string,object>(){ {"Name1","n2" } } },
31+
};
32+
33+
public static IQueryable<OpenType> CreateQuery()
34+
{
35+
return items.AsQueryable();
36+
}
37+
38+
public static IQueryable<OpenType> CreateQueryWithNotNullDictionary()
39+
{
40+
return itemsWithNotNullDictionary.AsQueryable();
41+
}
42+
43+
public static IQueryable<OpenType> CreateQueryWithAllProperties()
44+
{
45+
return itemsWithAllProperties.AsQueryable();
46+
}
47+
}
48+
}

Community.Data.OData.Linq/Community.OData.Linq.csproj

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,16 @@
1111
<PackageProjectUrl>https://github.com/IharYakimush/comminity-data-odata-linq</PackageProjectUrl>
1212
<RepositoryType></RepositoryType>
1313
<PackageTags>odata filter linq</PackageTags>
14-
<PackageReleaseNotes>Added support for $select and $expand parameters</PackageReleaseNotes>
14+
<PackageReleaseNotes>Fixed SelectExpand usage with EntityFramework
15+
Fixed usage of OData linq extensions after OrderBy
16+
Allowed filter by dynamic properties for open types in InMemory providers (https://github.com/IharYakimush/comminity-data-odata-linq/issues/10)</PackageReleaseNotes>
1517
<Description>Use OData filter text query in linq expresson for any IQuerable without ASP.NET dependency</Description>
1618
<Company />
1719
<RepositoryUrl></RepositoryUrl>
18-
<Version>1.1.0</Version>
20+
<Version>1.2.0</Version>
1921
<NeutralLanguage>en</NeutralLanguage>
20-
<AssemblyVersion>1.1.0.0</AssemblyVersion>
21-
<FileVersion>1.1.0.0</FileVersion>
22+
<AssemblyVersion>1.2.0.0</AssemblyVersion>
23+
<FileVersion>1.2.0.0</FileVersion>
2224
</PropertyGroup>
2325

2426
<ItemGroup>

Community.Data.OData.Linq/OData/Formatter/EdmLibHelpers.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace Community.OData.Linq.OData.Formatter
1212
using System.Linq;
1313
using System.Reflection;
1414
using System.Xml.Linq;
15-
15+
using Community.OData.Linq.Builder;
1616
using Community.OData.Linq.Common;
1717
using Community.OData.Linq.OData.Query;
1818
using Community.OData.Linq.OData.Query.Expressions;
@@ -705,12 +705,12 @@ public static PropertyInfo GetDynamicPropertyDictionary(IEdmStructuredType edmTy
705705
throw Error.ArgumentNull("edmModel");
706706
}
707707

708-
//DynamicPropertyDictionaryAnnotation annotation =
709-
// edmModel.GetAnnotationValue<DynamicPropertyDictionaryAnnotation>(edmType);
710-
//if (annotation != null)
711-
//{
712-
// return annotation.PropertyInfo;
713-
//}
708+
DynamicPropertyDictionaryAnnotation annotation =
709+
edmModel.GetAnnotationValue<DynamicPropertyDictionaryAnnotation>(edmType);
710+
if (annotation != null)
711+
{
712+
return annotation.PropertyInfo;
713+
}
714714

715715
return null;
716716
}

Community.Data.OData.Linq/OdataLinqExtensions.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,13 @@ public static IEnumerable<ISelectExpandWrapper> SelectExpand<T>(
118118

119119
var result = helper.Apply(query);
120120

121-
// In case of SelectExpand ,ethod was called to convert to ISelectExpandWrapper without actually applying $select and $expand params
121+
// In case of SelectExpand ,method was called to convert to ISelectExpandWrapper without actually applying $select and $expand params
122122
if (result == query && selectText==null && expandText == null)
123123
{
124124
return SelectExpand(query, "*", expandText, entitySetName);
125125
}
126126

127-
return result.OfType<ISelectExpandWrapper>();
127+
return Enumerate<ISelectExpandWrapper>(result);
128128
}
129129

130130
/// <summary>
@@ -199,7 +199,7 @@ public static ODataQuery<T> Filter<T>(this ODataQuery<T> query, string filterTex
199199
/// <exception cref="ArgumentNullException">
200200
/// Argument Null Exception
201201
/// </exception>
202-
public static IOrderedQueryable<T> OrderBy<T>(this ODataQuery<T> query, string orderbyText, string entitySetName = null)
202+
public static ODataQueryOrdered<T> OrderBy<T>(this ODataQuery<T> query, string orderbyText, string entitySetName = null)
203203
{
204204
if (query == null) throw new ArgumentNullException(nameof(query));
205205
if (orderbyText == null) throw new ArgumentNullException(nameof(orderbyText));
@@ -227,6 +227,16 @@ public static IOrderedQueryable<T> OrderBy<T>(this ODataQuery<T> query, string o
227227
return new ODataQueryOrdered<T>(result, query.ServiceProvider);
228228
}
229229

230+
private static IEnumerable<T> Enumerate<T>(IQueryable queryable) where T : class
231+
{
232+
var enumerator = queryable.GetEnumerator();
233+
234+
while (enumerator.MoveNext())
235+
{
236+
yield return enumerator.Current as T;
237+
}
238+
}
239+
230240
private static OrderByClause TranslateParameterAlias(OrderByClause orderBy, ODataQueryOptionParser queryOptionParser)
231241
{
232242
if (orderBy == null)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
4+
<connectionStrings>
5+
<add name="SchoolContext" connectionString="Data Source=localhost,10001;Initial Catalog=model;Persist Security Info=True;User ID=sa;Password=sapwdlocal@123" providerName="System.Data.SqlClient" />
6+
</connectionStrings>
7+
8+
</configuration>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net45</TargetFramework>
5+
<ApplicationIcon />
6+
<OutputType>Exe</OutputType>
7+
<StartupObject />
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<PackageReference Include="EntityFramework" Version="6.2.0" />
12+
</ItemGroup>
13+
14+
<ItemGroup>
15+
<ProjectReference Include="..\Community.Data.OData.Linq\Community.OData.Linq.csproj" />
16+
<ProjectReference Include="..\Community.OData.Linq.Json\Community.OData.Linq.Json.csproj" />
17+
</ItemGroup>
18+
19+
</Project>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System;
2+
using System.Data.Entity;
3+
using System.Data.Entity.SqlServer;
4+
5+
namespace ContosoUniversity.DAL
6+
{
7+
public class SchoolConfiguration : DbConfiguration
8+
{
9+
public SchoolConfiguration()
10+
{
11+
SetExecutionStrategy("System.Data.SqlClient", () => new SqlAzureExecutionStrategy(3, new TimeSpan(0,0,5)));
12+
}
13+
}
14+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using ContosoUniversity.Models;
2+
using System.Data.Entity;
3+
using System.Data.Entity.ModelConfiguration.Conventions;
4+
using System.Diagnostics;
5+
6+
namespace ContosoUniversity.DAL
7+
{
8+
public class SchoolContext : DbContext
9+
{
10+
public DbSet<Course> Courses { get; set; }
11+
public DbSet<Department> Departments { get; set; }
12+
public DbSet<Enrollment> Enrollments { get; set; }
13+
public DbSet<Instructor> Instructors { get; set; }
14+
public DbSet<Student> Students { get; set; }
15+
public DbSet<OfficeAssignment> OfficeAssignments { get; set; }
16+
public DbSet<Person> People { get; set; }
17+
18+
public SchoolContext()
19+
{
20+
Database.Log = s => Debug.WriteLine(s);
21+
}
22+
23+
protected override void OnModelCreating(DbModelBuilder modelBuilder)
24+
{
25+
modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
26+
27+
modelBuilder.Entity<Course>()
28+
.HasMany(c => c.Instructors).WithMany(i => i.Courses)
29+
.Map(t => t.MapLeftKey("CourseID")
30+
.MapRightKey("InstructorID")
31+
.ToTable("CourseInstructor"));
32+
33+
modelBuilder.Entity<Department>().MapToStoredProcedures();
34+
}
35+
}
36+
}

0 commit comments

Comments
 (0)