Fix interface property lookup in generic method

This commit is contained in:
Rhodon
2023-05-04 14:09:11 +02:00
parent 3b98b1ef36
commit aab4834002
2 changed files with 66 additions and 32 deletions
@@ -20,8 +20,20 @@ namespace EntityFrameworkCore.Projectables.FunctionalTests
[UsesVerify]
public class InheritedModelTests
{
public interface IBaseProvider<TBase>
{
ICollection<TBase> Bases { get; set; }
}
public class BaseProvider : IBaseProvider<Concrete>
{
public int Id { get; set; }
public ICollection<Concrete> Bases { get; set; }
}
public interface IBase
{
int Id { get; }
int ComputedProperty { get; }
int ComputedMethod();
}
@@ -117,6 +129,26 @@ namespace EntityFrameworkCore.Projectables.FunctionalTests
return Verifier.Verify(query.ToQueryString());
}
[Fact]
public Task ProjectOverProvider()
{
using var dbContext = new SampleDbContext<BaseProvider>();
var query = dbContext.Set<BaseProvider>().AllBases<BaseProvider, Concrete>();
return Verifier.Verify(query.ToQueryString());
}
[Fact]
public Task ProjectOverExtensionMethod()
{
using var dbContext = new SampleDbContext<Concrete>();
var query = dbContext.Set<Concrete>().Select(c => c.ComputedPropertyPlusMethod());
return Verifier.Verify(query.ToQueryString());
}
}
public static class ModelExtensions
@@ -128,5 +160,15 @@ namespace EntityFrameworkCore.Projectables.FunctionalTests
public static IQueryable<int> SelectComputedMethod<TConcrete>(this IQueryable<TConcrete> concretes)
where TConcrete : InheritedModelTests.IBase
=> concretes.Select(x => x.ComputedMethod());
public static IQueryable<int> AllBases<TProvider, TBase>(this IQueryable<TProvider> concretes)
where TProvider : InheritedModelTests.IBaseProvider<TBase>
where TBase : InheritedModelTests.IBase
=> concretes.SelectMany(x => x.Bases).Select(x => x.Id);
[Projectable]
public static int ComputedPropertyPlusMethod<TConcrete>(this TConcrete concrete)
where TConcrete : InheritedModelTests.IBase
=> concrete.ComputedProperty + concrete.ComputedMethod();
}
}