Skip to content

Commit

Permalink
Merge branch 'release/0.30.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
hazzik committed Dec 14, 2021
2 parents b4d56cf + 42cd539 commit 6a2046e
Show file tree
Hide file tree
Showing 42 changed files with 902 additions and 200 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace DelegateDecompiler.EntityFramework.Tests.EfItems.Abstracts
{
#if EF_CORE
public class AtlanticCod : Fish<int>
{
public override string Species => "Gadus morhua";
}
#endif
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace DelegateDecompiler.EntityFramework.Tests.EfItems.Abstracts
{
#if EF_CORE
public abstract class Fish : LivingBeeing
{
[Computed]
public abstract string Group { get; }
}

public abstract class Fish<T> : Fish
{
public override string Group => "Fish";
}
#endif
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace DelegateDecompiler.EntityFramework.Tests.EfItems.Abstracts
{
#if EF_CORE
public class WhiteShark : Fish<string>
{
public override string Species => "Carcharodon carcharias";
}
#endif
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ private static ICollection<LivingBeeing> InitializeLivingBeeings()
animal2,
new HoneyBee(),
new HoneyBee(),
#if EF_CORE
new AtlanticCod() { Age = 4 },
new WhiteShark() { Age = 1 },
#endif
new Person {Age = 1, Birthdate = new DateTime(1900, 1, 1), Name = "Joseph"},
new Person {Age = 2, Birthdate = new DateTime(1900, 1, 2), Name = "Maria"},
new Person
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#if EF_CORE
using DelegateDecompiler.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Diagnostics;
using DbModelBuilder = Microsoft.EntityFrameworkCore.ModelBuilder;
#else
using System.Data.Entity;
Expand All @@ -16,12 +17,20 @@ namespace DelegateDecompiler.EntityFramework.Tests.EfItems
{
public class EfTestDbContext : DbContext
{

#if EF_CORE
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
var connectionString = GetConnectionString();
optionsBuilder.UseSqlServer(connectionString);
#if EF_CORE5
optionsBuilder.LogTo((id, _) => id == RelationalEventId.CommandExecuted, d =>
{
if (Log != null && d is CommandExecutedEventData e)
{
Log(e.Command.CommandText);
}
});
#endif
}
#else
static EfTestDbContext()
Expand Down Expand Up @@ -55,6 +64,8 @@ static string GetConnectionString()

public DbSet<LivingBeeing> LivingBeeing { get; set; }

public Action<string> Log { get; set; }

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<EfPerson>()
Expand All @@ -64,6 +75,13 @@ protected override void OnModelCreating(DbModelBuilder modelBuilder)
modelBuilder.Entity<Dog>();
modelBuilder.Entity<HoneyBee>();
modelBuilder.Entity<Person>();
#if EF_CORE
modelBuilder.Entity<Fish>();
modelBuilder.Entity<Fish<string>>().HasBaseType<Fish>();
modelBuilder.Entity<Fish<int>>().HasBaseType<Fish>();
modelBuilder.Entity<WhiteShark>().HasBaseType<Fish<string>>();
modelBuilder.Entity<AtlanticCod>().HasBaseType<Fish<int>>();
#endif
base.OnModelCreating(modelBuilder);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Detail of supported commands
============
## Documentation produced for DelegateDecompiler, version 0.29.0 on Thursday, 04 February 2021 16:03
## Documentation produced for DelegateDecompiler, version 0.30.0 on Tuesday, 14 December 2021 22:20

This file documents what linq commands **DelegateDecompiler** supports when
working with [Entity Framework v6.1](http://msdn.microsoft.com/en-us/data/aa937723) (EF).
Expand Down Expand Up @@ -32,15 +32,16 @@ More will appear as we move forward.*
* Select Method Without Computed Attribute (line 104)
* Select Abstract Member Over Tph Hierarchy (line 121)
* Select Abstract Member Over Tph Hierarchy After Restricting To Subtype (line 138)
* Select Multiple Levels Of Abstract Members Over Tph Hierarchy (line 155)
* Select Multiple Levels Of Abstract Members Over Tph Hierarchy (line 199)

#### [Select Async](../TestGroup05BasicFeatures/Test02SelectAsync.cs):
- Supported
* Async (line 39)
* Bool Equals Constant Async (line 56)
* Decompile Upfront Bool Equals Constant Async (line 73)
* Bool Equals Static Variable To Array Async (line 92)
* Int Equals Constant (line 109)
* Async Non Generic (line 57)
* Bool Equals Constant Async (line 75)
* Decompile Upfront Bool Equals Constant Async (line 92)
* Bool Equals Static Variable To Array Async (line 111)
* Int Equals Constant (line 128)

#### [Equals And Not Equals](../TestGroup05BasicFeatures/Test03EqualsAndNotEquals.cs):
- Supported
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Detail With Sql of supported commands
============
## Documentation produced for DelegateDecompiler, version 0.29.0 on Thursday, 04 February 2021 16:03
## Documentation produced for DelegateDecompiler, version 0.30.0 on Tuesday, 14 December 2021 22:20

This file documents what linq commands **DelegateDecompiler** supports when
working with [Entity Framework v6.1](http://msdn.microsoft.com/en-us/data/aa937723) (EF).
Expand Down Expand Up @@ -90,7 +90,7 @@ SELECT
WHERE ([Extent1].[Discriminator] IN (N'Dog',N'HoneyBee',N'Person')) AND ([Extent1].[Discriminator] IN (N'Dog',N'HoneyBee'))
```

* Select Multiple Levels Of Abstract Members Over Tph Hierarchy (line 155)
* Select Multiple Levels Of Abstract Members Over Tph Hierarchy (line 199)
* T-Sql executed is

```SQL
Expand Down Expand Up @@ -122,7 +122,26 @@ SELECT
FROM [dbo].[EfParents] AS [Extent1]
```

* Bool Equals Constant Async (line 56)
* Async Non Generic (line 57)
* T-Sql executed is

```SQL
SELECT
[Extent1].[EfParentId] AS [EfParentId],
[Extent1].[ParentBool] AS [ParentBool],
[Extent1].[ParentInt] AS [ParentInt],
[Extent1].[ParentNullableInt] AS [ParentNullableInt],
[Extent1].[ParentNullableDecimal1] AS [ParentNullableDecimal1],
[Extent1].[ParentNullableDecimal2] AS [ParentNullableDecimal2],
[Extent1].[ParentDouble] AS [ParentDouble],
[Extent1].[ParentString] AS [ParentString],
[Extent1].[StartDate] AS [StartDate],
[Extent1].[EndDate] AS [EndDate],
[Extent1].[ParentTimeSpan] AS [ParentTimeSpan]
FROM [dbo].[EfParents] AS [Extent1]
```

* Bool Equals Constant Async (line 75)
* T-Sql executed is

```SQL
Expand All @@ -131,7 +150,7 @@ SELECT
FROM [dbo].[EfParents] AS [Extent1]
```

* Decompile Upfront Bool Equals Constant Async (line 73)
* Decompile Upfront Bool Equals Constant Async (line 92)
* T-Sql executed is

```SQL
Expand All @@ -140,7 +159,7 @@ SELECT
FROM [dbo].[EfParents] AS [Extent1]
```

* Bool Equals Static Variable To Array Async (line 92)
* Bool Equals Static Variable To Array Async (line 111)
* T-Sql executed is

```SQL
Expand All @@ -149,7 +168,7 @@ SELECT
FROM [dbo].[EfParents] AS [Extent1]
```

* Int Equals Constant (line 109)
* Int Equals Constant (line 128)
* T-Sql executed is

```SQL
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Summary of supported commands
============
## Documentation produced for DelegateDecompiler, version 0.29.0 on Thursday, 04 February 2021 16:03
## Documentation produced for DelegateDecompiler, version 0.30.0 on Tuesday, 14 December 2021 22:20

This file documents what linq commands **DelegateDecompiler** supports when
working with [Entity Framework v6.1](http://msdn.microsoft.com/en-us/data/aa937723) (EF).
Expand All @@ -25,7 +25,7 @@ More will appear as we move forward.*
### Group: Basic Features
- Supported
* [Select](../TestGroup05BasicFeatures/Test01Select.cs) (8 tests)
* [Select Async](../TestGroup05BasicFeatures/Test02SelectAsync.cs) (5 tests)
* [Select Async](../TestGroup05BasicFeatures/Test02SelectAsync.cs) (6 tests)
* [Equals And Not Equals](../TestGroup05BasicFeatures/Test03EqualsAndNotEquals.cs) (4 tests)
* [Nullable](../TestGroup05BasicFeatures/Test04Nullable.cs) (5 tests)
* [Where](../TestGroup05BasicFeatures/Test05Where.cs) (5 tests)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Contributed by @JonPSmith (GitHub) www.thereformedprogrammer.com

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
Expand All @@ -25,7 +26,25 @@ public static void CompareAndLogList<T>(this MethodEnvironment env, IList<T> lin
env.LogFailer(sourceLineNumber);
throw;
}
env.LogSuccess(sourceLineNumber);
env.LogSuccess(sourceLineNumber);
}

public static void CompareAndLogNonGenericList(this MethodEnvironment env, IList linqResult, IList ddResult,
[CallerLineNumber] int sourceLineNumber = 0)
{
if (linqResult.Count == 0)
throw new ArgumentException("The linq result was empty, so this was not a fair test.");

try
{
CollectionAssert.AreEqual(linqResult, ddResult);
}
catch (Exception)
{
env.LogFailer(sourceLineNumber);
throw;
}
env.LogSuccess(sourceLineNumber);
}

public static void CompareAndLogSingleton<T>(this MethodEnvironment env, T linqResult, T ddResult,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public MethodEnvironment(ClassEnvironment classEnv,
#if !EF_CORE
Db.Database.Log = LogEfSql; //capture the sql for the linq part
#else
//TODO: Caputre log?
Db.Log = LogEfSql; //capture the sql for the linq part
#endif
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,50 @@ public void TestSelectAbstractMemberOverTphHierarchyAfterRestrictingToSubtype()
}
}

#if EF_CORE
[Test]
public void TestSelectAbstractMemberOverTphHierarchyWithGenericClassesAfterRestrictingToSubtype()
{
using (var env = new MethodEnvironment(classEnv))
{
//SETUP
var linq = env.Db.LivingBeeing.OfType<Fish>().ToList().Select(p => new { p.Species, p.Group }).ToList();

//ATTEMPT
env.AboutToUseDelegateDecompiler();
var dd = env.Db.LivingBeeing.OfType<Fish>().Select(p => new { p.Species, p.Group }).Decompile().ToList();

//VERIFY
env.CompareAndLogList(linq, dd);
}
}

[Test]
public void TestSelectAbstractMemberWithConditionOnItOverTphHierarchyWithGenericClassesAfterRestrictingToSubtype()
{
using (var env = new MethodEnvironment(classEnv))
{
//SETUP
var linq = env.Db.LivingBeeing.OfType<Fish>().ToList()
.Select(p => new { p.Species, p.Group })
.Where(p => p.Species != null && p.Group != null)
.ToList();

//ATTEMPT
env.AboutToUseDelegateDecompiler();
var dd1 = env.Db.LivingBeeing.OfType<Fish>()
.Select(p => new { p.Species, p.Group })
.Where(p => p.Species != null && p.Group != null)
.Decompile();

var dd = dd1.ToList();

//VERIFY
env.CompareAndLogList(linq, dd);
}
}
#endif

[Test]
public void TestSelectMultipleLevelsOfAbstractMembersOverTphHierarchy()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,25 @@ public async Task TestAsync()
}
}

#if !EF_CORE
[Test]
public async Task TestAsyncNonGeneric()
{
using (var env = new MethodEnvironment(classEnv))
{
//SETUP
var linq = await env.Db.EfParents.ToListAsync();

//ATTEMPT
env.AboutToUseDelegateDecompiler();
var dd = await ((IQueryable)env.Db.EfParents).DecompileAsync().ToListAsync();

//VERIFY
env.CompareAndLogNonGenericList(linq, dd);
}
}
#endif

[Test]
public async Task TestBoolEqualsConstantAsync()
{
Expand Down
5 changes: 5 additions & 0 deletions src/DelegateDecompiler.EntityFramework/DecompileExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,10 @@ public static IQueryable<T> DecompileAsync<T>(this IQueryable<T> self)
{
return new AsyncDecompiledQueryProvider(self.Provider).CreateQuery<T>(self.Expression);
}

public static IQueryable DecompileAsync(this IQueryable self)
{
return new AsyncDecompiledQueryProvider(self.Provider).CreateQuery(self.Expression);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netcoreapp2.1;netcoreapp3.1</TargetFrameworks>
<TargetFrameworks>netcoreapp3.1</TargetFrameworks>
<Copyright>Copyright © Dave Glick 2014, Jon Smith 2014, Alexander Zaytsev 2014 - 2021</Copyright>
<DefineConstants>$(DefineConstants);EF_CORE</DefineConstants>
<RootNamespace>DelegateDecompiler.EntityFramework.Tests</RootNamespace>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Detail of supported commands
============
## Documentation produced for DelegateDecompiler, version 0.29.0 on Thursday, 04 February 2021 16:04
## Documentation produced for DelegateDecompiler, version 0.30.0 on Tuesday, 14 December 2021 22:21

This file documents what linq commands **DelegateDecompiler** supports when
working with [Entity Framework Core](https://docs.microsoft.com/en-us/ef/core/) (EF).
Expand Down Expand Up @@ -32,15 +32,17 @@ More will appear as we move forward.*
* Select Method Without Computed Attribute (line 104)
* Select Abstract Member Over Tph Hierarchy (line 121)
* Select Abstract Member Over Tph Hierarchy After Restricting To Subtype (line 138)
* Select Multiple Levels Of Abstract Members Over Tph Hierarchy (line 155)
* Select Abstract Member Over Tph Hierarchy With Generic Classes After Restricting To Subtype (line 156)
* Select Abstract Member With Condition On It Over Tph Hierarchy With Generic Classes After Restricting To Subtype (line 181)
* Select Multiple Levels Of Abstract Members Over Tph Hierarchy (line 199)

#### [Select Async](../TestGroup05BasicFeatures/Test02SelectAsync.cs):
- Supported
* Async (line 39)
* Bool Equals Constant Async (line 56)
* Decompile Upfront Bool Equals Constant Async (line 73)
* Bool Equals Static Variable To Array Async (line 92)
* Int Equals Constant (line 109)
* Bool Equals Constant Async (line 75)
* Decompile Upfront Bool Equals Constant Async (line 92)
* Bool Equals Static Variable To Array Async (line 111)
* Int Equals Constant (line 128)

#### [Equals And Not Equals](../TestGroup05BasicFeatures/Test03EqualsAndNotEquals.cs):
- Supported
Expand Down
Loading

0 comments on commit 6a2046e

Please sign in to comment.