mirror of
https://github.com/zoriya/EntityFrameworkCore.Projectables.git
synced 2026-08-15 18:44:57 +00:00
Add support for concrete interface implementations
Change overriding member logic to use MethodInfo.GetBaseDefinition()
This commit is contained in:
+2
@@ -0,0 +1,2 @@
|
||||
SELECT 2
|
||||
FROM [Concrete] AS [c]
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
SELECT 2
|
||||
FROM [Concrete] AS [c]
|
||||
+1
-1
@@ -1,2 +1,2 @@
|
||||
SELECT 2
|
||||
FROM [Concrete] AS [c]
|
||||
FROM [MoreConcrete] AS [m]
|
||||
+1
-1
@@ -1,2 +1,2 @@
|
||||
SELECT 2
|
||||
FROM [Concrete] AS [c]
|
||||
FROM [MoreConcrete] AS [m]
|
||||
@@ -20,7 +20,13 @@ namespace EntityFrameworkCore.Projectables.FunctionalTests
|
||||
[UsesVerify]
|
||||
public class InheritedModelTests
|
||||
{
|
||||
public abstract class Base
|
||||
public interface IBase
|
||||
{
|
||||
int ComputedProperty { get; }
|
||||
int ComputedMethod();
|
||||
}
|
||||
|
||||
public abstract class Base : IBase
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
@@ -62,9 +68,9 @@ namespace EntityFrameworkCore.Projectables.FunctionalTests
|
||||
[Fact]
|
||||
public Task ProjectOverInheritedPropertyImplementation()
|
||||
{
|
||||
using var dbContext = new SampleDbContext<Concrete>();
|
||||
using var dbContext = new SampleDbContext<MoreConcrete>();
|
||||
|
||||
var query = dbContext.Set<Concrete>()
|
||||
var query = dbContext.Set<MoreConcrete>()
|
||||
.Select(x => x.ComputedProperty);
|
||||
|
||||
return Verifier.Verify(query.ToQueryString());
|
||||
@@ -84,12 +90,43 @@ namespace EntityFrameworkCore.Projectables.FunctionalTests
|
||||
[Fact]
|
||||
public Task ProjectOverInheritedMethodImplementation()
|
||||
{
|
||||
using var dbContext = new SampleDbContext<Concrete>();
|
||||
using var dbContext = new SampleDbContext<MoreConcrete>();
|
||||
|
||||
var query = dbContext.Set<Concrete>()
|
||||
var query = dbContext.Set<MoreConcrete>()
|
||||
.Select(x => x.ComputedMethod());
|
||||
|
||||
return Verifier.Verify(query.ToQueryString());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public Task ProjectOverImplementedProperty()
|
||||
{
|
||||
using var dbContext = new SampleDbContext<Concrete>();
|
||||
|
||||
var query = dbContext.Set<Concrete>().SelectComputedProperty();
|
||||
|
||||
return Verifier.Verify(query.ToQueryString());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public Task ProjectOverImplementedMethod()
|
||||
{
|
||||
using var dbContext = new SampleDbContext<Concrete>();
|
||||
|
||||
var query = dbContext.Set<Concrete>().SelectComputedMethod();
|
||||
|
||||
return Verifier.Verify(query.ToQueryString());
|
||||
}
|
||||
}
|
||||
|
||||
public static class ModelExtensions
|
||||
{
|
||||
public static IQueryable<int> SelectComputedProperty<TConcrete>(this IQueryable<TConcrete> concretes)
|
||||
where TConcrete : InheritedModelTests.IBase
|
||||
=> concretes.Select(x => x.ComputedProperty);
|
||||
|
||||
public static IQueryable<int> SelectComputedMethod<TConcrete>(this IQueryable<TConcrete> concretes)
|
||||
where TConcrete : InheritedModelTests.IBase
|
||||
=> concretes.Select(x => x.ComputedMethod());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user