Skip to content

Commit 62f4c22

Browse files
authored
Merge pull request #77 from AutoMapper/SupportNetStandardWithEF6
Tests - supporting netstandard2.1 with EF6 v6.3.
2 parents f2884c8 + 58cd737 commit 62f4c22

37 files changed

+2294
-55
lines changed

AutoMapper.AspNet.OData.EF6/AutoMapper.AspNet.OData.EF6.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<PackageId>AutoMapper.AspNet.OData.EF6</PackageId>
77
<Description>Creates LINQ expressions from ODataQueryOptions and executes the query.</Description>
88
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
9-
<PackageReleaseNotes>Incorporating v.latest from AutoMapper.Extensions.ExpressionMapping</PackageReleaseNotes>
9+
<PackageReleaseNotes>Supporting EF6 through .NetStandard 2.1.</PackageReleaseNotes>
1010
<PackageTags>linq expressions odata ef</PackageTags>
1111
<PackageIconUrl>https://s3.amazonaws.com/automapper/icon.png</PackageIconUrl>
1212
<RepositoryUrl>https://github.com/AutoMapper/AutoMapper.Extensions.OData</RepositoryUrl>

AutoMapper.AspNetCore.OData.EF6/AutoMapper.AspNetCore.OData.EF6.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net461</TargetFramework>
4+
<TargetFrameworks>netstandard2.1;net461</TargetFrameworks>
55
<RootNamespace>AutoMapper.AspNet.OData</RootNamespace>
66
<PackageId>AutoMapper.AspNetCore.OData.EF6</PackageId>
77
<Description>Creates LINQ expressions from ODataQueryOptions and executes the query.</Description>
88
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
9-
<PackageReleaseNotes>Incorporating v.latest from AutoMapper.Extensions.ExpressionMapping</PackageReleaseNotes>
9+
<PackageReleaseNotes>Supporting EF6 through .NetStandard 2.1.</PackageReleaseNotes>
1010
<PackageTags>linq expressions odata efcore</PackageTags>
1111
<PackageIconUrl>https://s3.amazonaws.com/automapper/icon.png</PackageIconUrl>
1212
<RepositoryUrl>https://github.com/AutoMapper/AutoMapper.Extensions.OData</RepositoryUrl>
@@ -41,7 +41,7 @@
4141

4242
<ItemGroup>
4343
<PackageReference Include="AutoMapper.Extensions.ExpressionMapping" Version="[4.0.2,5.0.0)" />
44-
<PackageReference Include="EntityFramework" Version="6.2.0" />
44+
<PackageReference Include="EntityFramework" Version="6.3.0" />
4545
<PackageReference Include="LogicBuilder.Expressions.Utils" Version="4.0.2" />
4646
<PackageReference Include="Microsoft.AspNetCore.OData" Version="7.4.1" />
4747
<PackageReference Include="MinVer" Version="2.3.0">

AutoMapper.AspNetCore.OData.EFCore/AutoMapper.AspNetCore.OData.EFCore.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<PackageId>AutoMapper.AspNetCore.OData.EFCore</PackageId>
77
<Description>Creates LINQ expressions from ODataQueryOptions and executes the query.</Description>
88
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
9-
<PackageReleaseNotes>Incorporating v.latest from AutoMapper.Extensions.ExpressionMapping</PackageReleaseNotes>
9+
<PackageReleaseNotes>Supporting EF6 through .NetStandard 2.1.</PackageReleaseNotes>
1010
<PackageTags>linq expressions odata efcore</PackageTags>
1111
<PackageIconUrl>https://s3.amazonaws.com/automapper/icon.png</PackageIconUrl>
1212
<RepositoryUrl>https://github.com/AutoMapper/AutoMapper.Extensions.OData</RepositoryUrl>

AutoMapper.Extensions.OData.sln

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MigrationTool", "MigrationT
4545
EndProject
4646
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SeedDatabase", "SeedDatabase\SeedDatabase.csproj", "{CE492720-2000-4533-93AF-5AA71A65D305}"
4747
EndProject
48+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutoMapper.OData.EF6.Tests", "AutoMapper.OData.EF6.Tests\AutoMapper.OData.EF6.Tests.csproj", "{BF11CF7F-0424-46F7-A60E-B614525C68C7}"
49+
EndProject
50+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebAPI.OData.EF6", "WebAPI.OData.EF6\WebAPI.OData.EF6.csproj", "{4C069416-CF7B-45C7-8C8F-B3D24DC16D01}"
51+
EndProject
52+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DAL.EF6", "DAL.EF6\DAL.EF6.csproj", "{8139DB48-8A96-405A-9B02-44C4AEF79FD0}"
53+
EndProject
4854
Global
4955
GlobalSection(SolutionConfigurationPlatforms) = preSolution
5056
Debug|Any CPU = Debug|Any CPU
@@ -101,6 +107,16 @@ Global
101107
{CE492720-2000-4533-93AF-5AA71A65D305}.Debug|Any CPU.Build.0 = Debug|Any CPU
102108
{CE492720-2000-4533-93AF-5AA71A65D305}.Release|Any CPU.ActiveCfg = Release|Any CPU
103109
{CE492720-2000-4533-93AF-5AA71A65D305}.Release|Any CPU.Build.0 = Release|Any CPU
110+
{BF11CF7F-0424-46F7-A60E-B614525C68C7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
111+
{BF11CF7F-0424-46F7-A60E-B614525C68C7}.Debug|Any CPU.Build.0 = Debug|Any CPU
112+
{BF11CF7F-0424-46F7-A60E-B614525C68C7}.Release|Any CPU.ActiveCfg = Release|Any CPU
113+
{BF11CF7F-0424-46F7-A60E-B614525C68C7}.Release|Any CPU.Build.0 = Release|Any CPU
114+
{4C069416-CF7B-45C7-8C8F-B3D24DC16D01}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
115+
{4C069416-CF7B-45C7-8C8F-B3D24DC16D01}.Release|Any CPU.ActiveCfg = Release|Any CPU
116+
{8139DB48-8A96-405A-9B02-44C4AEF79FD0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
117+
{8139DB48-8A96-405A-9B02-44C4AEF79FD0}.Debug|Any CPU.Build.0 = Debug|Any CPU
118+
{8139DB48-8A96-405A-9B02-44C4AEF79FD0}.Release|Any CPU.ActiveCfg = Release|Any CPU
119+
{8139DB48-8A96-405A-9B02-44C4AEF79FD0}.Release|Any CPU.Build.0 = Release|Any CPU
104120
EndGlobalSection
105121
GlobalSection(SolutionProperties) = preSolution
106122
HideSolutionNode = FALSE
@@ -120,6 +136,9 @@ Global
120136
{64E80DBD-A61B-42A0-A0DB-4F36921EB83B} = {3E35C7A6-722E-46FE-AFE0-2EFDF668DB44}
121137
{13B74DC7-6A33-4F6D-879A-CB5F6FC5D73D} = {D2A273B8-0229-4121-8189-175960E7749D}
122138
{CE492720-2000-4533-93AF-5AA71A65D305} = {D2A273B8-0229-4121-8189-175960E7749D}
139+
{BF11CF7F-0424-46F7-A60E-B614525C68C7} = {3E35C7A6-722E-46FE-AFE0-2EFDF668DB44}
140+
{4C069416-CF7B-45C7-8C8F-B3D24DC16D01} = {D2A273B8-0229-4121-8189-175960E7749D}
141+
{8139DB48-8A96-405A-9B02-44C4AEF79FD0} = {D2A273B8-0229-4121-8189-175960E7749D}
123142
EndGlobalSection
124143
GlobalSection(ExtensibilityGlobals) = postSolution
125144
SolutionGuid = {8A39B99E-1717-408D-9655-27AFFFB4798C}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netcoreapp3.1</TargetFramework>
5+
6+
<IsPackable>false</IsPackable>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
11+
<PackageReference Include="xunit" Version="2.4.1" />
12+
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" />
13+
<PackageReference Include="coverlet.collector" Version="1.2.0" />
14+
</ItemGroup>
15+
16+
<ItemGroup>
17+
<ProjectReference Include="..\AutoMapper.AspNetCore.OData.EF6\AutoMapper.AspNetCore.OData.EF6.csproj" />
18+
<ProjectReference Include="..\DAL.EF6\DAL.EF6.csproj" />
19+
<ProjectReference Include="..\Domain.OData\Domain.OData.csproj" />
20+
</ItemGroup>
21+
22+
</Project>
Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
//Adapted from Microsoft.AspNet.OData.Test.Query.Expressions
2+
using Microsoft.AspNet.OData.Query;
3+
using Microsoft.OData.Edm;
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Linq;
7+
using System.Xml.Linq;
8+
9+
namespace AutoMapper.OData.EF6.Tests.Data
10+
{
11+
public class Product
12+
{
13+
public int ProductID { get; set; }
14+
15+
public string ProductName { get; set; }
16+
public int SupplierID { get; set; }
17+
public int CategoryID { get; set; }
18+
public string QuantityPerUnit { get; set; }
19+
public decimal? UnitPrice { get; set; }
20+
public double? Weight { get; set; }
21+
public float? Width { get; set; }
22+
public short? UnitsInStock { get; set; }
23+
public short? UnitsOnOrder { get; set; }
24+
25+
public short? ReorderLevel { get; set; }
26+
public bool? Discontinued { get; set; }
27+
public DateTimeOffset? DiscontinuedDate { get; set; }
28+
public System.DateTime Birthday { get; set; }
29+
30+
public DateTimeOffset NonNullableDiscontinuedDate { get; set; }
31+
[NotFilterable]
32+
public DateTimeOffset NotFilterableDiscontinuedDate { get; set; }
33+
34+
public DateTimeOffset DiscontinuedOffset { get; set; }
35+
public TimeSpan DiscontinuedSince { get; set; }
36+
37+
public Date DateProperty { get; set; }
38+
public Date? NullableDateProperty { get; set; }
39+
40+
public Guid GuidProperty { get; set; }
41+
public Guid? NullableGuidProperty { get; set; }
42+
43+
public TimeOfDay TimeOfDayProperty { get; set; }
44+
public TimeOfDay? NullableTimeOfDayProperty { get; set; }
45+
46+
public ushort? UnsignedReorderLevel { get; set; }
47+
48+
public SimpleEnum Ranking { get; set; }
49+
50+
public Category Category { get; set; }
51+
52+
public Address SupplierAddress { get; set; }
53+
54+
public int[] AlternateIDs { get; set; }
55+
public Address[] AlternateAddresses { get; set; }
56+
[NotFilterable]
57+
public Address[] NotFilterableAlternateAddresses { get; set; }
58+
}
59+
60+
public class Category
61+
{
62+
public int CategoryID { get; set; }
63+
public string CategoryName { get; set; }
64+
65+
public Product Product { get; set; }
66+
67+
public ICollection<Product> Products { get; set; }
68+
69+
public IEnumerable<Product> EnumerableProducts { get; set; }
70+
public IQueryable<Product> QueryableProducts { get; set; }
71+
}
72+
73+
public class Address
74+
{
75+
public int AddressID { get; set; }
76+
public string City { get; set; }
77+
public string State { get; set; }
78+
public string ZipCode { get; set; }
79+
}
80+
81+
public class DataTypes
82+
{
83+
public int Id { get; set; }
84+
public Guid GuidProp { get; set; }
85+
public DateTimeOffset DateTimeProp { get; set; }
86+
public DateTimeOffset DateTimeOffsetProp { get; set; }
87+
public byte[] ByteArrayProp { get; set; }
88+
public byte[] ByteArrayPropWithNullValue { get; set; }
89+
public TimeSpan TimeSpanProp { get; set; }
90+
public decimal DecimalProp { get; set; }
91+
public double DoubleProp { get; set; }
92+
public float FloatProp { get; set; }
93+
public Single SingleProp { get; set; }
94+
public long LongProp { get; set; }
95+
public int IntProp { get; set; }
96+
public string StringProp { get; set; }
97+
public bool BoolProp { get; set; }
98+
99+
public ushort UShortProp { get; set; }
100+
public uint UIntProp { get; set; }
101+
public ulong ULongProp { get; set; }
102+
public char CharProp { get; set; }
103+
public byte ByteProp { get; set; }
104+
105+
public short? NullableShortProp { get; set; }
106+
public int? NullableIntProp { get; set; }
107+
public long? NullableLongProp { get; set; }
108+
public Single? NullableSingleProp { get; set; }
109+
public double? NullableDoubleProp { get; set; }
110+
public decimal? NullableDecimalProp { get; set; }
111+
public bool? NullableBoolProp { get; set; }
112+
public byte? NullableByteProp { get; set; }
113+
public Guid? NullableGuidProp { get; set; }
114+
public DateTimeOffset? NullableDateTimeOffsetProp { get; set; }
115+
public TimeSpan? NullableTimeSpanProp { get; set; }
116+
117+
public ushort? NullableUShortProp { get; set; }
118+
public uint? NullableUIntProp { get; set; }
119+
public ulong? NullableULongProp { get; set; }
120+
public char? NullableCharProp { get; set; }
121+
122+
public char[] CharArrayProp { get; set; }
123+
public XElement XElementProp { get; set; }
124+
125+
public SimpleEnum SimpleEnumProp { get; set; }
126+
public FlagsEnum FlagsEnumProp { get; set; }
127+
public LongEnum LongEnumProp { get; set; }
128+
public SimpleEnum? NullableSimpleEnumProp { get; set; }
129+
130+
public Product EntityProp { get; set; }
131+
public Address ComplexProp { get; set; }
132+
133+
public string Inaccessible() { return string.Empty; }
134+
}
135+
136+
public class DerivedProduct : Product
137+
{
138+
public string DerivedProductName { get; set; }
139+
}
140+
141+
public class DerivedCategory : Category
142+
{
143+
public string DerivedCategoryName { get; set; }
144+
}
145+
146+
public class DynamicProduct : Product
147+
{
148+
public Dictionary<string, object> ProductProperties { get; set; }
149+
}
150+
151+
[Flags]
152+
public enum FlagsEnum
153+
{
154+
One = 0x1,
155+
Two = 0x2,
156+
Four = 0x4
157+
}
158+
159+
public enum SimpleEnum
160+
{
161+
First,
162+
Second,
163+
Third,
164+
Fourth
165+
}
166+
167+
public enum LongEnum : long
168+
{
169+
FirstLong,
170+
SecondLong,
171+
ThirdLong,
172+
FourthLong
173+
}
174+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
using DAL.EF6;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Data.Entity;
5+
using System.Linq;
6+
7+
namespace AutoMapper.OData.EF6.Tests.Data
8+
{
9+
public class DatabaseInitializer : DropCreateDatabaseAlways<TestDbContext>
10+
{
11+
protected override void Seed(TestDbContext context)
12+
{
13+
context.City.Add(new TCity { Name = "London" });
14+
context.City.Add(new TCity { Name = "Leeds" });
15+
context.SaveChanges();
16+
17+
List<TCity> cities = context.City.ToList();
18+
context.Builder.Add(new TBuilder { Name = "Sam", CityId = cities.First(b => b.Name == "London").Id });
19+
context.Builder.Add(new TBuilder { Name = "John", CityId = cities.First(b => b.Name == "London").Id });
20+
context.Builder.Add(new TBuilder { Name = "Mark", CityId = cities.First(b => b.Name == "Leeds").Id });
21+
context.SaveChanges();
22+
23+
List<TBuilder> builders = context.Builder.ToList();
24+
context.MandatorSet.Add(new TMandator
25+
{
26+
Identity = Guid.NewGuid(),
27+
Name = "One",
28+
Buildings = new List<TBuilding>
29+
{
30+
new TBuilding { Identity = Guid.NewGuid(), LongName = "One L1", BuilderId = builders.First(b => b.Name == "Sam").Id },
31+
new TBuilding { Identity = Guid.NewGuid(), LongName = "One L2", BuilderId = builders.First(b => b.Name == "Sam").Id }
32+
}
33+
});
34+
context.MandatorSet.Add(new TMandator
35+
{
36+
Identity = Guid.NewGuid(),
37+
Name = "Two",
38+
Buildings = new List<TBuilding>
39+
{
40+
new TBuilding { Identity = Guid.NewGuid(), LongName = "Two L1", BuilderId = builders.First(b => b.Name == "John").Id },
41+
new TBuilding { Identity = Guid.NewGuid(), LongName = "Two L2", BuilderId = builders.First(b => b.Name == "Mark").Id },
42+
new TBuilding { Identity = Guid.NewGuid(), LongName = "Two L3", BuilderId = builders.First(b => b.Name == "Mark").Id }
43+
}
44+
});
45+
context.SaveChanges();
46+
47+
base.Seed(context);
48+
}
49+
}
50+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System.Data.Entity;
2+
using System.Data.Entity.Infrastructure;
3+
4+
namespace AutoMapper.OData.EF6.Tests.Data
5+
{
6+
public class TestDbConfiguration : DbConfiguration
7+
{
8+
public TestDbConfiguration()
9+
{
10+
SetDefaultConnectionFactory(new LocalDbConnectionFactory("MSSQLLocalDB"));
11+
}
12+
}
13+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using DAL.EF6;
2+
using System.Data.Entity;
3+
4+
namespace AutoMapper.OData.EF6.Tests.Data
5+
{
6+
public class TestDbContext : DbContext
7+
{
8+
public TestDbContext()
9+
{
10+
Configuration.LazyLoadingEnabled = false;
11+
Configuration.AutoDetectChangesEnabled = false;
12+
Configuration.ProxyCreationEnabled = false;
13+
Database.SetInitializer(new DatabaseInitializer());
14+
}
15+
16+
protected override void OnModelCreating(DbModelBuilder modelBuilder)
17+
{
18+
modelBuilder.Entity<TMandator>()
19+
.HasMany(x => x.Buildings)
20+
.WithRequired(x => x.Mandator)
21+
.HasForeignKey(x => x.MandatorId);
22+
}
23+
24+
public IDbSet<TMandator> MandatorSet { get; set; }
25+
26+
public IDbSet<TBuilding> BuildingSet { get; set; }
27+
28+
public IDbSet<TBuilder> Builder { get; set; }
29+
30+
public IDbSet<TCity> City { get; set; }
31+
32+
}
33+
}

0 commit comments

Comments
 (0)