mirror of
https://github.com/zoriya/EntityFrameworkCore.Projectables.git
synced 2026-06-02 23:02:11 +00:00
Fix interface property lookup in generic method
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user