diff --git a/src/EntityFrameworkCore.Projectables.Generator/DeclarationSyntaxRewriter.cs b/src/EntityFrameworkCore.Projectables.Generator/DeclarationSyntaxRewriter.cs index d897599..1dd5875 100644 --- a/src/EntityFrameworkCore.Projectables.Generator/DeclarationSyntaxRewriter.cs +++ b/src/EntityFrameworkCore.Projectables.Generator/DeclarationSyntaxRewriter.cs @@ -15,21 +15,6 @@ namespace EntityFrameworkCore.Projectables.Generator _semanticModel = semanticModel; } - public override SyntaxNode? VisitIdentifierName(IdentifierNameSyntax node) - { - var visitedNode = base.VisitIdentifierName(node); - - var symbolInfo = _semanticModel.GetSymbolInfo(visitedNode); - - if (symbolInfo.Symbol is not null) - { - return SyntaxFactory.IdentifierName(symbolInfo.Symbol.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)) - .WithTriviaFrom(node); - } - - return visitedNode; - } - public override SyntaxNode? VisitParameter(ParameterSyntax node) { var visitedNode = base.VisitParameter(node); diff --git a/src/EntityFrameworkCore.Projectables.Generator/ProjectableDescriptor.cs b/src/EntityFrameworkCore.Projectables.Generator/ProjectableDescriptor.cs index d1b0ef6..b4805bb 100644 --- a/src/EntityFrameworkCore.Projectables.Generator/ProjectableDescriptor.cs +++ b/src/EntityFrameworkCore.Projectables.Generator/ProjectableDescriptor.cs @@ -2,6 +2,7 @@ using Microsoft.CodeAnalysis.CSharp.Syntax; using System; using System.Collections.Generic; +using System.Collections.Immutable; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -28,6 +29,10 @@ namespace EntityFrameworkCore.Projectables.Generator public ParameterListSyntax ParametersList { get; set; } + public TypeParameterListSyntax TypeParameterList { get; set; } + + public IEnumerable ConstraintClauses { get; set; } + public SyntaxNode Body { get; set; } } } diff --git a/src/EntityFrameworkCore.Projectables.Generator/ProjectableInterpreter.cs b/src/EntityFrameworkCore.Projectables.Generator/ProjectableInterpreter.cs index 3d3c911..29d65a2 100644 --- a/src/EntityFrameworkCore.Projectables.Generator/ProjectableInterpreter.cs +++ b/src/EntityFrameworkCore.Projectables.Generator/ProjectableInterpreter.cs @@ -59,7 +59,8 @@ namespace EntityFrameworkCore.Projectables.Generator ClassNamespace = memberSymbol.ContainingType.ContainingNamespace.IsGlobalNamespace ? null : memberSymbol.ContainingType.ContainingNamespace.ToDisplayString(), MemberName = memberSymbol.Name, NestedInClassNames = GetNestedInClassPath(memberSymbol.ContainingType), - ParametersList = SyntaxFactory.ParameterList() + ParametersList = SyntaxFactory.ParameterList(), + TypeParameterList = SyntaxFactory.TypeParameterList() }; if (!memberDeclarationSyntax.Modifiers.Any(SyntaxKind.StaticKeyword)) @@ -78,7 +79,9 @@ namespace EntityFrameworkCore.Projectables.Generator ); } - if (memberSymbol is IMethodSymbol methodSymbol && methodSymbol.IsExtensionMethod) + var methodSymbol = memberSymbol as IMethodSymbol; + + if (methodSymbol is { IsExtensionMethod: true }) { var targetTypeSymbol = methodSymbol.Parameters.First().Type; descriptor.TargetClassNamespace = targetTypeSymbol.ContainingNamespace.IsGlobalNamespace ? null : targetTypeSymbol.ContainingNamespace.ToDisplayString(); @@ -107,6 +110,20 @@ namespace EntityFrameworkCore.Projectables.Generator { descriptor.ParametersList = descriptor.ParametersList.AddParameters(additionalParameter); } + + if (methodDeclarationSyntax.TypeParameterList is not null) + { + foreach (var additionalTypeParameter in ((TypeParameterListSyntax)declarationSyntaxRewriter.Visit(methodDeclarationSyntax.TypeParameterList)).Parameters) + { + descriptor.TypeParameterList = descriptor.TypeParameterList.AddParameters(additionalTypeParameter); + } + } + + if (methodDeclarationSyntax.ConstraintClauses.Any()) + { + descriptor.ConstraintClauses = methodDeclarationSyntax.ConstraintClauses + .Select(x => (TypeParameterConstraintClauseSyntax)declarationSyntaxRewriter.Visit(x)); + } } else if (memberDeclarationSyntax is PropertyDeclarationSyntax propertyDeclarationSyntax) { diff --git a/src/EntityFrameworkCore.Projectables.Generator/ProjectionExpressionGenerator.cs b/src/EntityFrameworkCore.Projectables.Generator/ProjectionExpressionGenerator.cs index 3eab520..b70fe11 100644 --- a/src/EntityFrameworkCore.Projectables.Generator/ProjectionExpressionGenerator.cs +++ b/src/EntityFrameworkCore.Projectables.Generator/ProjectionExpressionGenerator.cs @@ -72,11 +72,26 @@ namespace EntityFrameworkCore.Projectables.Generated {{ public static class {generatedClassName} {{ - public static System.Linq.Expressions.Expression> Expression => - {projectable.ParametersList} => {projectable.Body}; + public static System.Linq.Expressions.Expression> Expression{(projectable.TypeParameterList.Parameters.Any() ? projectable.TypeParameterList.ToString() : string.Empty)}()"); + + if (projectable.ConstraintClauses is not null) + { + foreach (var constraintClause in projectable.ConstraintClauses) + { + resultBuilder.Append($@" + {constraintClause}"); + } + } + + resultBuilder.Append($@" + {{ + return {projectable.ParametersList} => + {projectable.Body}; + }} }} }}"); + context.AddSource($"{generatedClassName}_Generated", SourceText.From(resultBuilder.ToString(), Encoding.UTF8)); } } diff --git a/src/EntityFrameworkCore.Projectables/Services/ProjectionExpressionResolver.cs b/src/EntityFrameworkCore.Projectables/Services/ProjectionExpressionResolver.cs index 2d68057..699ea3f 100644 --- a/src/EntityFrameworkCore.Projectables/Services/ProjectionExpressionResolver.cs +++ b/src/EntityFrameworkCore.Projectables/Services/ProjectionExpressionResolver.cs @@ -12,31 +12,37 @@ namespace EntityFrameworkCore.Projectables.Services { public sealed class ProjectionExpressionResolver : IProjectionExpressionResolver { - readonly ConcurrentDictionary _lookupCache = new(); - public LambdaExpression FindGeneratedExpression(MemberInfo projectableMemberInfo) { var reflectedType = projectableMemberInfo.ReflectedType ?? throw new InvalidOperationException("Expected a valid type here"); var generatedContainingTypeName = ProjectionExpressionClassNameGenerator.GenerateFullName(reflectedType.Namespace, reflectedType.GetNestedTypePath().Select(x => x.Name), projectableMemberInfo.Name); - return _lookupCache.GetOrAdd(generatedContainingTypeName, _ => { - var expressionFactoryMethod = reflectedType.Assembly - .GetTypes() - .Where(x => x.FullName == generatedContainingTypeName) - .SelectMany(x => x.GetMethods()) - .FirstOrDefault(); + var genericArguments = projectableMemberInfo switch { + MethodInfo methodInfo => methodInfo.GetGenericArguments(), + _ => null + }; - if (expressionFactoryMethod is null) - { - throw new InvalidOperationException("Unable to resolve generated expression") { - Data = { - ["GeneratedContainingTypeName"] = generatedContainingTypeName - } - }; - } + var expressionFactoryMethod = reflectedType.Assembly + .GetTypes() + .Where(x => x.FullName == generatedContainingTypeName) + .SelectMany(x => x.GetMethods()) + .FirstOrDefault(); - return expressionFactoryMethod.Invoke(null, null) as LambdaExpression ?? throw new InvalidOperationException("Expected lambda"); - }); + if (expressionFactoryMethod is null) + { + throw new InvalidOperationException("Unable to resolve generated expression") { + Data = { + ["GeneratedContainingTypeName"] = generatedContainingTypeName + } + }; + } + + if (genericArguments is { Length: > 0 } ) + { + expressionFactoryMethod = expressionFactoryMethod.MakeGenericMethod(genericArguments); + } + + return expressionFactoryMethod.Invoke(null, null) as LambdaExpression ?? throw new InvalidOperationException("Expected lambda"); } } } diff --git a/tests/EntityFrameworkCore.Projectables.FunctionalTests/ExtensionsMethods/ExtensionMethodTests.cs b/tests/EntityFrameworkCore.Projectables.FunctionalTests/ExtensionsMethods/ExtensionMethodTests.cs index fdfe87e..723ceee 100644 --- a/tests/EntityFrameworkCore.Projectables.FunctionalTests/ExtensionsMethods/ExtensionMethodTests.cs +++ b/tests/EntityFrameworkCore.Projectables.FunctionalTests/ExtensionsMethods/ExtensionMethodTests.cs @@ -63,4 +63,4 @@ namespace EntityFrameworkCore.Projectables.FunctionalTests.ExtensionMethods return Verifier.Verify(query.ToQueryString()); } } -} +} \ No newline at end of file diff --git a/tests/EntityFrameworkCore.Projectables.FunctionalTests/Generics/Entity.cs b/tests/EntityFrameworkCore.Projectables.FunctionalTests/Generics/Entity.cs new file mode 100644 index 0000000..d0de2bb --- /dev/null +++ b/tests/EntityFrameworkCore.Projectables.FunctionalTests/Generics/Entity.cs @@ -0,0 +1,8 @@ +namespace EntityFrameworkCore.Projectables.FunctionalTests.Generics +{ + public record Entity : IEntity + { + public int Id { get; set; } + public string? Name { get; set; } + } +} diff --git a/tests/EntityFrameworkCore.Projectables.FunctionalTests/Generics/EntityExtensions.cs b/tests/EntityFrameworkCore.Projectables.FunctionalTests/Generics/EntityExtensions.cs new file mode 100644 index 0000000..fd204a5 --- /dev/null +++ b/tests/EntityFrameworkCore.Projectables.FunctionalTests/Generics/EntityExtensions.cs @@ -0,0 +1,11 @@ +using System.Linq; + +namespace EntityFrameworkCore.Projectables.FunctionalTests.Generics +{ + public static class EntityExtensions + { + [Projectable] + public static TEntity? DefaultIfIdIsNegative(this TEntity entity) where TEntity : IEntity + => entity.Id >= 0 ? entity : default; + } +} diff --git a/tests/EntityFrameworkCore.Projectables.FunctionalTests/Generics/GenericExtensionMethodTests.cs b/tests/EntityFrameworkCore.Projectables.FunctionalTests/Generics/GenericExtensionMethodTests.cs new file mode 100644 index 0000000..3ba3517 --- /dev/null +++ b/tests/EntityFrameworkCore.Projectables.FunctionalTests/Generics/GenericExtensionMethodTests.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using EntityFrameworkCore.Projectables.FunctionalTests.Helpers; +using Microsoft.EntityFrameworkCore; +using VerifyXunit; +using Xunit; + +namespace EntityFrameworkCore.Projectables.FunctionalTests.Generics +{ + [UsesVerify] + public class GenericFunctionTests + { + [Fact] + public Task DefaultIfIdIsNegative() + { + using var context = new SampleDbContext(); + var query = context.Set() + .Select(x => x.DefaultIfIdIsNegative()); + + return Verifier.Verify(query.ToQueryString()); + } + } +} diff --git a/tests/EntityFrameworkCore.Projectables.FunctionalTests/Generics/GenericFunctionTests.DefaultIfIdIsNegative.verified.txt b/tests/EntityFrameworkCore.Projectables.FunctionalTests/Generics/GenericFunctionTests.DefaultIfIdIsNegative.verified.txt new file mode 100644 index 0000000..5e39cab --- /dev/null +++ b/tests/EntityFrameworkCore.Projectables.FunctionalTests/Generics/GenericFunctionTests.DefaultIfIdIsNegative.verified.txt @@ -0,0 +1,5 @@ +SELECT CASE + WHEN [e].[Id] >= 0 THEN CAST(1 AS bit) + ELSE CAST(0 AS bit) +END, [e].[Id], [e].[Name] +FROM [Entity] AS [e] \ No newline at end of file diff --git a/tests/EntityFrameworkCore.Projectables.FunctionalTests/Generics/GenericFunctionTests.QueryOrderedByDefault.verified.txt b/tests/EntityFrameworkCore.Projectables.FunctionalTests/Generics/GenericFunctionTests.QueryOrderedByDefault.verified.txt new file mode 100644 index 0000000..772dbc0 --- /dev/null +++ b/tests/EntityFrameworkCore.Projectables.FunctionalTests/Generics/GenericFunctionTests.QueryOrderedByDefault.verified.txt @@ -0,0 +1,3 @@ +SELECT [e].[Id] +FROM [Entity] AS [e] +ORDER BY [e].[Id] \ No newline at end of file diff --git a/tests/EntityFrameworkCore.Projectables.FunctionalTests/Generics/IEntity.cs b/tests/EntityFrameworkCore.Projectables.FunctionalTests/Generics/IEntity.cs new file mode 100644 index 0000000..14d1119 --- /dev/null +++ b/tests/EntityFrameworkCore.Projectables.FunctionalTests/Generics/IEntity.cs @@ -0,0 +1,7 @@ +namespace EntityFrameworkCore.Projectables.FunctionalTests.Generics +{ + public interface IEntity + { + int Id { get; } + } +} diff --git a/tests/EntityFrameworkCore.Projectables.FunctionalTests/Generics/MultipleGenericsTests.TestMultipleArguments.verified.txt b/tests/EntityFrameworkCore.Projectables.FunctionalTests/Generics/MultipleGenericsTests.TestMultipleArguments.verified.txt new file mode 100644 index 0000000..fe2dca8 --- /dev/null +++ b/tests/EntityFrameworkCore.Projectables.FunctionalTests/Generics/MultipleGenericsTests.TestMultipleArguments.verified.txt @@ -0,0 +1,2 @@ +SELECT CAST(1 AS bit), [e].[Id], [e].[Name] +FROM [Entity] AS [e] \ No newline at end of file diff --git a/tests/EntityFrameworkCore.Projectables.FunctionalTests/Generics/MultipleGenericsTests.cs b/tests/EntityFrameworkCore.Projectables.FunctionalTests/Generics/MultipleGenericsTests.cs new file mode 100644 index 0000000..d6029b1 --- /dev/null +++ b/tests/EntityFrameworkCore.Projectables.FunctionalTests/Generics/MultipleGenericsTests.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using EntityFrameworkCore.Projectables.FunctionalTests.Helpers; +using Microsoft.EntityFrameworkCore; +using VerifyXunit; +using Xunit; + +namespace EntityFrameworkCore.Projectables.FunctionalTests.Generics +{ + [UsesVerify] + public class MultipleGenericsTests + { + [Projectable] + public static object? Coalesce(T1? t1, T2 t2) + => t1 != null ? t1 : t2; + + [Fact] + public Task TestMultipleArguments() + { + using var context = new SampleDbContext(); + + var query = context.Set() + .Select(x => Coalesce(x.Id, x.Name)); + + return Verifier.Verify(query.ToQueryString()); + } + + + [Fact] + public void MultipleInvocations() + { + using var context = new SampleDbContext(Infrastructure.CompatibilityMode.Full); + + var query1 = context.Set() + .Select(x => Coalesce(x.Id, x.Name)) + .ToQueryString(); + + var query2 = context.Set() + .Select(x => Coalesce(x.Name, x.Id)) + .ToQueryString(); + + Assert.NotEqual(query1, query2); + } + } +} diff --git a/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.ArgumentlessProjectableComputedMethod.verified.txt b/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.ArgumentlessProjectableComputedMethod.verified.txt index d0258be..b85bcaa 100644 --- a/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.ArgumentlessProjectableComputedMethod.verified.txt +++ b/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.ArgumentlessProjectableComputedMethod.verified.txt @@ -7,7 +7,10 @@ namespace EntityFrameworkCore.Projectables.Generated { public static class Foo_C_Foo { - public static System.Linq.Expressions.Expression> Expression => - (global::Foo.C @this) => 0; + public static System.Linq.Expressions.Expression> Expression() + { + return (global::Foo.C @this) => + 0; + } } } \ No newline at end of file diff --git a/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.GenericMethods_AreRewritten.verified.txt b/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.GenericMethods_AreRewritten.verified.txt new file mode 100644 index 0000000..e5b8a4f --- /dev/null +++ b/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.GenericMethods_AreRewritten.verified.txt @@ -0,0 +1,19 @@ +using System; +using System.Linq; +using System.Collections.Generic; +using EntityFrameworkCore.Projectables; +using Foo; + +namespace EntityFrameworkCore.Projectables.Generated +#nullable disable +{ + public static class Foo_EntityExtensions_EnforceString + { + public static System.Linq.Expressions.Expression> Expression() + where T : unmanaged + { + return (T value) => + value.ToString(); + } + } +} \ No newline at end of file diff --git a/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.GenericNullableReferenceTypesAreBeingEliminated.verified.txt b/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.GenericNullableReferenceTypesAreBeingEliminated.verified.txt index 8c7c916..cc66f09 100644 --- a/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.GenericNullableReferenceTypesAreBeingEliminated.verified.txt +++ b/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.GenericNullableReferenceTypesAreBeingEliminated.verified.txt @@ -9,7 +9,10 @@ namespace EntityFrameworkCore.Projectables.Generated { public static class Foo_C_NextFoo { - public static System.Linq.Expressions.Expression ,List, List>> Expression => - (List input,List nullablePrimitiveArgument) => input; + public static System.Linq.Expressions.Expression ,List, List>> Expression() + { + return (List input,List nullablePrimitiveArgument) => + input; + } } } \ No newline at end of file diff --git a/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.MoreComplexProjectableComputedProperty.verified.txt b/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.MoreComplexProjectableComputedProperty.verified.txt index abd064c..caa415e 100644 --- a/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.MoreComplexProjectableComputedProperty.verified.txt +++ b/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.MoreComplexProjectableComputedProperty.verified.txt @@ -7,7 +7,10 @@ namespace EntityFrameworkCore.Projectables.Generated { public static class Foo_C_Foo { - public static System.Linq.Expressions.Expression> Expression => - (global::Foo.C @this) => @this.Bar + @this.Bar + @this.Bar; + public static System.Linq.Expressions.Expression> Expression() + { + return (global::Foo.C @this) => + @this.Bar + @this.Bar + @this.Bar; + } } } \ No newline at end of file diff --git a/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.NullableElementAndMemberBinding_WithIgnoreSupport_IsBeingRewritten.verified.txt b/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.NullableElementAndMemberBinding_WithIgnoreSupport_IsBeingRewritten.verified.txt index 0d229f9..4085a48 100644 --- a/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.NullableElementAndMemberBinding_WithIgnoreSupport_IsBeingRewritten.verified.txt +++ b/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.NullableElementAndMemberBinding_WithIgnoreSupport_IsBeingRewritten.verified.txt @@ -9,7 +9,10 @@ namespace EntityFrameworkCore.Projectables.Generated { public static class Foo_EntityExtensions_GetFirstRelatedIgnoreNulls { - public static System.Linq.Expressions.Expression> Expression => - (global::Foo.EntityExtensions.Entity entity) => entity.RelatedEntities[0]; + public static System.Linq.Expressions.Expression> Expression() + { + return (Entity entity) => + entity.RelatedEntities[0]; + } } } \ No newline at end of file diff --git a/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.NullableElementAndMemberBinding_WithRewriteSupport_IsBeingRewritten.verified.txt b/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.NullableElementAndMemberBinding_WithRewriteSupport_IsBeingRewritten.verified.txt index c62b9bc..4ff2555 100644 --- a/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.NullableElementAndMemberBinding_WithRewriteSupport_IsBeingRewritten.verified.txt +++ b/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.NullableElementAndMemberBinding_WithRewriteSupport_IsBeingRewritten.verified.txt @@ -9,7 +9,10 @@ namespace EntityFrameworkCore.Projectables.Generated { public static class Foo_EntityExtensions_GetFirstRelatedIgnoreNulls { - public static System.Linq.Expressions.Expression> Expression => - (global::Foo.EntityExtensions.Entity entity) => entity != null ? (entity.RelatedEntities != null ? (entity.RelatedEntities[0]) : null) : null; + public static System.Linq.Expressions.Expression> Expression() + { + return (Entity entity) => + entity != null ? (entity.RelatedEntities != null ? (entity.RelatedEntities[0]) : null) : null; + } } } \ No newline at end of file diff --git a/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.NullableElementBinding_WithIgnoreSupport_IsBeingRewritten.verified.txt b/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.NullableElementBinding_WithIgnoreSupport_IsBeingRewritten.verified.txt index 223687e..fbcca3d 100644 --- a/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.NullableElementBinding_WithIgnoreSupport_IsBeingRewritten.verified.txt +++ b/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.NullableElementBinding_WithIgnoreSupport_IsBeingRewritten.verified.txt @@ -8,7 +8,10 @@ namespace EntityFrameworkCore.Projectables.Generated { public static class Foo_C_GetFirst { - public static System.Linq.Expressions.Expression> Expression => - (string input) => input[0].ToString(); + public static System.Linq.Expressions.Expression> Expression() + { + return (string input) => + input[0].ToString(); + } } } \ No newline at end of file diff --git a/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.NullableElementBinding_WithRewriteSupport_IsBeingRewritten.verified.txt b/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.NullableElementBinding_WithRewriteSupport_IsBeingRewritten.verified.txt index 37fb8ca..d1e609d 100644 --- a/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.NullableElementBinding_WithRewriteSupport_IsBeingRewritten.verified.txt +++ b/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.NullableElementBinding_WithRewriteSupport_IsBeingRewritten.verified.txt @@ -8,7 +8,10 @@ namespace EntityFrameworkCore.Projectables.Generated { public static class Foo_C_GetFirst { - public static System.Linq.Expressions.Expression> Expression => - (string input) => input != null ? (input[0].ToString()) : null; + public static System.Linq.Expressions.Expression> Expression() + { + return (string input) => + input != null ? (input[0].ToString()) : null; + } } } \ No newline at end of file diff --git a/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.NullableMemberBinding_WithIgnoreSupport_IsBeingRewritten.verified.txt b/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.NullableMemberBinding_WithIgnoreSupport_IsBeingRewritten.verified.txt index f9b3a83..1d12a36 100644 --- a/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.NullableMemberBinding_WithIgnoreSupport_IsBeingRewritten.verified.txt +++ b/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.NullableMemberBinding_WithIgnoreSupport_IsBeingRewritten.verified.txt @@ -8,7 +8,10 @@ namespace EntityFrameworkCore.Projectables.Generated { public static class Foo_C_GetLength { - public static System.Linq.Expressions.Expression> Expression => - (string input) => input.Length; + public static System.Linq.Expressions.Expression> Expression() + { + return (string input) => + input.Length; + } } } \ No newline at end of file diff --git a/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.NullableMemberBinding_WithRewriteSupport_IsBeingRewritten.verified.txt b/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.NullableMemberBinding_WithRewriteSupport_IsBeingRewritten.verified.txt index c729b9a..e507f92 100644 --- a/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.NullableMemberBinding_WithRewriteSupport_IsBeingRewritten.verified.txt +++ b/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.NullableMemberBinding_WithRewriteSupport_IsBeingRewritten.verified.txt @@ -8,7 +8,10 @@ namespace EntityFrameworkCore.Projectables.Generated { public static class Foo_C_GetLength { - public static System.Linq.Expressions.Expression> Expression => - (string input) => input != null ? (input.Length) : null; + public static System.Linq.Expressions.Expression> Expression() + { + return (string input) => + input != null ? (input.Length) : null; + } } } \ No newline at end of file diff --git a/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.NullableParameters_WithRewriteSupport_IsBeingRewritten.verified.txt b/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.NullableParameters_WithRewriteSupport_IsBeingRewritten.verified.txt index 0f4fbf8..a72ac27 100644 --- a/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.NullableParameters_WithRewriteSupport_IsBeingRewritten.verified.txt +++ b/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.NullableParameters_WithRewriteSupport_IsBeingRewritten.verified.txt @@ -9,7 +9,10 @@ namespace EntityFrameworkCore.Projectables.Generated { public static class Foo_EntityExtensions_GetFirstName { - public static System.Linq.Expressions.Expression> Expression => - (global::Foo.EntityExtensions.Entity entity) => entity.FullName != null ? (entity.FullName.Substring(entity.FullName != null ? (entity.FullName.IndexOf(' ') ) : null?? 0)) : null; + public static System.Linq.Expressions.Expression> Expression() + { + return (Entity entity) => + entity.FullName != null ? (entity.FullName.Substring(entity.FullName != null ? (entity.FullName.IndexOf(' ') ) : null?? 0)) : null; + } } } \ No newline at end of file diff --git a/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.NullableReferenceTypeCastOperatorGetsEliminated.verified.txt b/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.NullableReferenceTypeCastOperatorGetsEliminated.verified.txt index b8d948b..0744376 100644 --- a/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.NullableReferenceTypeCastOperatorGetsEliminated.verified.txt +++ b/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.NullableReferenceTypeCastOperatorGetsEliminated.verified.txt @@ -9,7 +9,10 @@ namespace EntityFrameworkCore.Projectables.Generated { public static class Foo_C_NullableReferenceType { - public static System.Linq.Expressions.Expression> Expression => - (object input) => (string)input; + public static System.Linq.Expressions.Expression> Expression() + { + return (object input) => + (string)input; + } } } \ No newline at end of file diff --git a/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.NullableReferenceTypesAreBeingEliminated.verified.txt b/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.NullableReferenceTypesAreBeingEliminated.verified.txt index 7995003..4267f51 100644 --- a/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.NullableReferenceTypesAreBeingEliminated.verified.txt +++ b/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.NullableReferenceTypesAreBeingEliminated.verified.txt @@ -8,7 +8,10 @@ namespace EntityFrameworkCore.Projectables.Generated { public static class Foo_C_NextFoo { - public static System.Linq.Expressions.Expression> Expression => - (object unusedArgument,int? nullablePrimitiveArgument) => null; + public static System.Linq.Expressions.Expression> Expression() + { + return (object unusedArgument,int? nullablePrimitiveArgument) => + null; + } } } \ No newline at end of file diff --git a/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.NullableSimpleElementBinding_WithIgnoreSupport_IsBeingRewritten.verified.txt b/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.NullableSimpleElementBinding_WithIgnoreSupport_IsBeingRewritten.verified.txt index 811dbf2..93a9e1f 100644 --- a/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.NullableSimpleElementBinding_WithIgnoreSupport_IsBeingRewritten.verified.txt +++ b/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.NullableSimpleElementBinding_WithIgnoreSupport_IsBeingRewritten.verified.txt @@ -8,7 +8,10 @@ namespace EntityFrameworkCore.Projectables.Generated { public static class Foo_C_GetFirst { - public static System.Linq.Expressions.Expression> Expression => - (string input) => input[0]; + public static System.Linq.Expressions.Expression> Expression() + { + return (string input) => + input[0]; + } } } \ No newline at end of file diff --git a/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.NullableSimpleElementBinding_WithRewriteSupport_IsBeingRewritten.verified.txt b/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.NullableSimpleElementBinding_WithRewriteSupport_IsBeingRewritten.verified.txt index 34c0099..8a6e048 100644 --- a/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.NullableSimpleElementBinding_WithRewriteSupport_IsBeingRewritten.verified.txt +++ b/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.NullableSimpleElementBinding_WithRewriteSupport_IsBeingRewritten.verified.txt @@ -8,7 +8,10 @@ namespace EntityFrameworkCore.Projectables.Generated { public static class Foo_C_GetFirst { - public static System.Linq.Expressions.Expression> Expression => - (string input) => input != null ? (input[0]) : null; + public static System.Linq.Expressions.Expression> Expression() + { + return (string input) => + input != null ? (input[0]) : null; + } } } \ No newline at end of file diff --git a/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.NullableValueCastOperatorsPersist.verified.txt b/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.NullableValueCastOperatorsPersist.verified.txt index e9aa28a..80493c1 100644 --- a/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.NullableValueCastOperatorsPersist.verified.txt +++ b/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.NullableValueCastOperatorsPersist.verified.txt @@ -9,7 +9,10 @@ namespace EntityFrameworkCore.Projectables.Generated { public static class Foo_C_NullableValueType { - public static System.Linq.Expressions.Expression> Expression => - (object input) => (int?)input; + public static System.Linq.Expressions.Expression> Expression() + { + return (object input) => + (int?)input; + } } } \ No newline at end of file diff --git a/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.ProjectableComputedMethodWithMultipleArguments.verified.txt b/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.ProjectableComputedMethodWithMultipleArguments.verified.txt index 9db5012..21a1c88 100644 --- a/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.ProjectableComputedMethodWithMultipleArguments.verified.txt +++ b/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.ProjectableComputedMethodWithMultipleArguments.verified.txt @@ -7,7 +7,10 @@ namespace EntityFrameworkCore.Projectables.Generated { public static class Foo_C_Foo { - public static System.Linq.Expressions.Expression> Expression => - (global::Foo.C @this,int a,string b,object d) => a; + public static System.Linq.Expressions.Expression> Expression() + { + return (global::Foo.C @this,int a,string b,object d) => + a; + } } } \ No newline at end of file diff --git a/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.ProjectableComputedMethodWithSingleArgument.verified.txt b/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.ProjectableComputedMethodWithSingleArgument.verified.txt index daa7653..d258c44 100644 --- a/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.ProjectableComputedMethodWithSingleArgument.verified.txt +++ b/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.ProjectableComputedMethodWithSingleArgument.verified.txt @@ -7,7 +7,10 @@ namespace EntityFrameworkCore.Projectables.Generated { public static class Foo_C_Foo { - public static System.Linq.Expressions.Expression> Expression => - (global::Foo.C @this,int i) => i; + public static System.Linq.Expressions.Expression> Expression() + { + return (global::Foo.C @this,int i) => + i; + } } } \ No newline at end of file diff --git a/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.ProjectableComputedPropertyMethod.verified.txt b/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.ProjectableComputedPropertyMethod.verified.txt index 969443d..17e1c8a 100644 --- a/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.ProjectableComputedPropertyMethod.verified.txt +++ b/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.ProjectableComputedPropertyMethod.verified.txt @@ -7,7 +7,10 @@ namespace EntityFrameworkCore.Projectables.Generated { public static class Foo_C_Foo { - public static System.Linq.Expressions.Expression> Expression => - (global::Foo.C @this) => @this.Bar(); + public static System.Linq.Expressions.Expression> Expression() + { + return (global::Foo.C @this) => + @this.Bar(); + } } } \ No newline at end of file diff --git a/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.ProjectableComputedPropertyUsingThis.verified.txt b/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.ProjectableComputedPropertyUsingThis.verified.txt index d505707..3b85da5 100644 --- a/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.ProjectableComputedPropertyUsingThis.verified.txt +++ b/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.ProjectableComputedPropertyUsingThis.verified.txt @@ -7,7 +7,10 @@ namespace EntityFrameworkCore.Projectables.Generated { public static class Foo_C_Foo { - public static System.Linq.Expressions.Expression> Expression => - (global::Foo.C @this) => @this.Bar; + public static System.Linq.Expressions.Expression> Expression() + { + return (global::Foo.C @this) => + @this.Bar; + } } } \ No newline at end of file diff --git a/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.ProjectableExtensionMethod.verified.txt b/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.ProjectableExtensionMethod.verified.txt index 1ab7a6e..75226c2 100644 --- a/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.ProjectableExtensionMethod.verified.txt +++ b/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.ProjectableExtensionMethod.verified.txt @@ -8,7 +8,10 @@ namespace EntityFrameworkCore.Projectables.Generated { public static class Foo_C_Foo { - public static System.Linq.Expressions.Expression> Expression => - (global::Foo.D d) => 1; + public static System.Linq.Expressions.Expression> Expression() + { + return (D d) => + 1; + } } } \ No newline at end of file diff --git a/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.ProjectableExtensionMethod2.verified.txt b/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.ProjectableExtensionMethod2.verified.txt index 860c71e..ccb2172 100644 --- a/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.ProjectableExtensionMethod2.verified.txt +++ b/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.ProjectableExtensionMethod2.verified.txt @@ -8,7 +8,10 @@ namespace EntityFrameworkCore.Projectables.Generated { public static class Foo_C_Foo { - public static System.Linq.Expressions.Expression> Expression => - (int i) => i; + public static System.Linq.Expressions.Expression> Expression() + { + return (int i) => + i; + } } } \ No newline at end of file diff --git a/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.ProjectableExtensionMethod3.verified.txt b/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.ProjectableExtensionMethod3.verified.txt index c3d8de4..b86bf56 100644 --- a/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.ProjectableExtensionMethod3.verified.txt +++ b/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.ProjectableExtensionMethod3.verified.txt @@ -8,7 +8,10 @@ namespace EntityFrameworkCore.Projectables.Generated { public static class Foo_C_Foo1 { - public static System.Linq.Expressions.Expression> Expression => - (int i) => i; + public static System.Linq.Expressions.Expression> Expression() + { + return (int i) => + i; + } } } \ No newline at end of file diff --git a/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.ProjectableExtensionMethod4.verified.txt b/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.ProjectableExtensionMethod4.verified.txt index d857b66..e6e98e4 100644 --- a/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.ProjectableExtensionMethod4.verified.txt +++ b/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.ProjectableExtensionMethod4.verified.txt @@ -8,7 +8,10 @@ namespace EntityFrameworkCore.Projectables.Generated { public static class Foo_C_Foo1 { - public static System.Linq.Expressions.Expression> Expression => - (object i) => i.Foo1(); + public static System.Linq.Expressions.Expression> Expression() + { + return (object i) => + i.Foo1(); + } } } \ No newline at end of file diff --git a/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.ProjectablePropertyToNavigationalProperty.verified.txt b/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.ProjectablePropertyToNavigationalProperty.verified.txt index f2ad130..ff27e37 100644 --- a/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.ProjectablePropertyToNavigationalProperty.verified.txt +++ b/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.ProjectablePropertyToNavigationalProperty.verified.txt @@ -8,7 +8,10 @@ namespace EntityFrameworkCore.Projectables.Generated { public static class Foo_C_Foo { - public static System.Linq.Expressions.Expression> Expression => - (global::Foo.C @this) => @this.Dees.First(); + public static System.Linq.Expressions.Expression> Expression() + { + return (global::Foo.C @this) => + @this.Dees.First(); + } } } \ No newline at end of file diff --git a/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.SimpleProjectableComputedInNestedClassProperty.verified.txt b/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.SimpleProjectableComputedInNestedClassProperty.verified.txt index c331b38..4ea3217 100644 --- a/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.SimpleProjectableComputedInNestedClassProperty.verified.txt +++ b/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.SimpleProjectableComputedInNestedClassProperty.verified.txt @@ -7,7 +7,10 @@ namespace EntityFrameworkCore.Projectables.Generated { public static class Foo_C_D_Foo { - public static System.Linq.Expressions.Expression> Expression => - (global::Foo.C.D @this) => @this.Bar + 1; + public static System.Linq.Expressions.Expression> Expression() + { + return (global::Foo.C.D @this) => + @this.Bar + 1; + } } } \ No newline at end of file diff --git a/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.SimpleProjectableComputedProperty.verified.txt b/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.SimpleProjectableComputedProperty.verified.txt index 71567ab..34484f1 100644 --- a/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.SimpleProjectableComputedProperty.verified.txt +++ b/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.SimpleProjectableComputedProperty.verified.txt @@ -7,7 +7,10 @@ namespace EntityFrameworkCore.Projectables.Generated { public static class Foo_C_Foo { - public static System.Linq.Expressions.Expression> Expression => - (global::Foo.C @this) => @this.Bar + 1; + public static System.Linq.Expressions.Expression> Expression() + { + return (global::Foo.C @this) => + @this.Bar + 1; + } } } \ No newline at end of file diff --git a/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.SimpleProjectableMethod.verified.txt b/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.SimpleProjectableMethod.verified.txt index 0914f89..ece435b 100644 --- a/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.SimpleProjectableMethod.verified.txt +++ b/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.SimpleProjectableMethod.verified.txt @@ -7,7 +7,10 @@ namespace EntityFrameworkCore.Projectables.Generated { public static class Foo_C_Foo { - public static System.Linq.Expressions.Expression> Expression => - (global::Foo.C @this) => 1; + public static System.Linq.Expressions.Expression> Expression() + { + return (global::Foo.C @this) => + 1; + } } } \ No newline at end of file diff --git a/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.SimpleProjectableProperty.verified.txt b/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.SimpleProjectableProperty.verified.txt index 0914f89..ece435b 100644 --- a/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.SimpleProjectableProperty.verified.txt +++ b/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.SimpleProjectableProperty.verified.txt @@ -7,7 +7,10 @@ namespace EntityFrameworkCore.Projectables.Generated { public static class Foo_C_Foo { - public static System.Linq.Expressions.Expression> Expression => - (global::Foo.C @this) => 1; + public static System.Linq.Expressions.Expression> Expression() + { + return (global::Foo.C @this) => + 1; + } } } \ No newline at end of file diff --git a/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.TypesInBodyGetsFullyQualified.verified.txt b/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.TypesInBodyGetsFullyQualified.verified.txt index 29de077..8b8e5ca 100644 --- a/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.TypesInBodyGetsFullyQualified.verified.txt +++ b/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.TypesInBodyGetsFullyQualified.verified.txt @@ -8,7 +8,10 @@ namespace EntityFrameworkCore.Projectables.Generated { public static class Foo_C_Foo { - public static System.Linq.Expressions.Expression> Expression => - (global::Foo.C @this) => @this.Dees.OfType().Count(); + public static System.Linq.Expressions.Expression> Expression() + { + return (global::Foo.C @this) => + @this.Dees.OfType().Count(); + } } } \ No newline at end of file diff --git a/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.cs b/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.cs index e1a8c68..c277987 100644 --- a/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.cs +++ b/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.cs @@ -834,6 +834,39 @@ namespace Foo { return Verifier.Verify(result.GeneratedTrees[0].ToString()); } + [Fact] + public Task GenericMethods_AreRewritten() + { + var compilation = CreateCompilation(@" +using System; +using System.Linq; +using System.Collections.Generic; +using EntityFrameworkCore.Projectables; + +namespace Foo { + public static class EntityExtensions + { + public record Entity + { + public int Id { get; set; } + public string? FullName { get; set; } + } + + [Projectable] + public static string EnforceString(T value) where T : unmanaged + => value.ToString(); + } +} +"); + + var result = RunGenerator(compilation); + + Assert.Empty(result.Diagnostics); + Assert.Single(result.GeneratedTrees); + + return Verifier.Verify(result.GeneratedTrees[0].ToString()); + } + #region Helpers Compilation CreateCompilation(string source, bool expectedToCompile = true)