mirror of
https://github.com/zoriya/EntityFrameworkCore.Projectables.git
synced 2026-05-14 07:54:38 +00:00
Fixed code gen issue for Projectable extension methods using other projectable extension methods
This commit is contained in:
@@ -51,7 +51,17 @@ namespace EntityFrameworkCore.Projectables.Generator
|
||||
|
||||
if (symbolInfo.Symbol is not null)
|
||||
{
|
||||
if (symbolInfo.Symbol.Kind is SymbolKind.Property or SymbolKind.Method or SymbolKind.Field && SymbolEqualityComparer.Default.Equals(symbolInfo.Symbol.ContainingType, _targetTypeSymbol))
|
||||
if (symbolInfo.Symbol is IMethodSymbol methodSymbol && methodSymbol.IsExtensionMethod)
|
||||
{
|
||||
if (SymbolEqualityComparer.Default.Equals(symbolInfo.Symbol.ContainingType, _targetTypeSymbol))
|
||||
{
|
||||
//return SyntaxFactory.MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression,
|
||||
// methodSymbol.ReducedFrom.Sym
|
||||
//);
|
||||
//throw new Exception("foo");
|
||||
}
|
||||
}
|
||||
else if (symbolInfo.Symbol.Kind is SymbolKind.Property or SymbolKind.Method or SymbolKind.Field && SymbolEqualityComparer.Default.Equals(symbolInfo.Symbol.ContainingType, _targetTypeSymbol))
|
||||
{
|
||||
return SyntaxFactory.MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression,
|
||||
SyntaxFactory.IdentifierName("@this"),
|
||||
|
||||
@@ -11,6 +11,9 @@ namespace EntityFrameworkCore.Projectables.FunctionalTests.ExtensionMethods
|
||||
[Projectable]
|
||||
public static int Foo(this Entity entity) => entity.Id + 1;
|
||||
|
||||
[Projectable]
|
||||
public static int Foo2(this Entity entity) => entity.Foo() + 1;
|
||||
|
||||
[Projectable]
|
||||
public static Entity? LeadingEntity(this Entity entity, DbContext dbContext)
|
||||
=> dbContext.Set<Entity>().Where(y => y.Id > entity.Id).FirstOrDefault();
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
SELECT ([e].[Id] + 1) + 1
|
||||
FROM [Entity] AS [e]
|
||||
@@ -38,6 +38,17 @@ namespace EntityFrameworkCore.Projectables.FunctionalTests.ExtensionMethods
|
||||
return Verifier.Verify(query.ToQueryString());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public Task SelectProjectableExtensionMethod2()
|
||||
{
|
||||
using var dbContext = new SampleDbContext<Entity>();
|
||||
|
||||
var query = dbContext.Set<Entity>()
|
||||
.Select(x => x.Foo2());
|
||||
|
||||
return Verifier.Verify(query.ToQueryString());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public Task ExtensionMethodAcceptingDbContext()
|
||||
{
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using EntityFrameworkCore.Projectables;
|
||||
using Foo;
|
||||
|
||||
namespace EntityFrameworkCore.Projectables.Generated
|
||||
#nullable disable
|
||||
{
|
||||
public static class Foo_C_Foo1
|
||||
{
|
||||
public static System.Linq.Expressions.Expression<System.Func<int, int>> Expression =>
|
||||
(int i) => i;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using EntityFrameworkCore.Projectables;
|
||||
using Foo;
|
||||
|
||||
namespace EntityFrameworkCore.Projectables.Generated
|
||||
#nullable disable
|
||||
{
|
||||
public static class Foo_C_Foo1
|
||||
{
|
||||
public static System.Linq.Expressions.Expression<System.Func<object, object>> Expression =>
|
||||
(object i) => i.Foo1();
|
||||
}
|
||||
}
|
||||
@@ -367,6 +367,56 @@ namespace Foo {
|
||||
return Verifier.Verify(result.GeneratedTrees[0].ToString());
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public Task ProjectableExtensionMethod3()
|
||||
{
|
||||
var compilation = CreateCompilation(@"
|
||||
using System;
|
||||
using System.Linq;
|
||||
using EntityFrameworkCore.Projectables;
|
||||
namespace Foo {
|
||||
static class C {
|
||||
[Projectable]
|
||||
public static int Foo1(this int i) => i;
|
||||
|
||||
[Projectable]
|
||||
public static int Foo2(this int i) => i.Foo1();
|
||||
}
|
||||
}
|
||||
");
|
||||
|
||||
var result = RunGenerator(compilation);
|
||||
|
||||
Assert.Empty(result.Diagnostics);
|
||||
Assert.Equal(2, result.GeneratedTrees.Length);
|
||||
|
||||
return Verifier.Verify(result.GeneratedTrees[0].ToString());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public Task ProjectableExtensionMethod4()
|
||||
{
|
||||
var compilation = CreateCompilation(@"
|
||||
using System;
|
||||
using System.Linq;
|
||||
using EntityFrameworkCore.Projectables;
|
||||
namespace Foo {
|
||||
static class C {
|
||||
[Projectable]
|
||||
public static object Foo1(this object i) => i.Foo1();
|
||||
}
|
||||
}
|
||||
");
|
||||
|
||||
var result = RunGenerator(compilation);
|
||||
|
||||
Assert.Empty(result.Diagnostics);
|
||||
Assert.Single(result.GeneratedTrees);
|
||||
|
||||
return Verifier.Verify(result.GeneratedTrees[0].ToString());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void BlockBodiedMember_RaisesDiagnostics()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user