mirror of
https://github.com/zoriya/EntityFrameworkCore.Projectables.git
synced 2026-05-27 12:31:47 +00:00
Fixed a regression where relational member calls would fail to generate
This commit is contained in:
@@ -127,7 +127,7 @@ namespace EntityFrameworkCore.Projectables.Generator
|
|||||||
if (symbolInfo.Symbol is IMethodSymbol methodSymbol && methodSymbol.IsExtensionMethod)
|
if (symbolInfo.Symbol is IMethodSymbol methodSymbol && methodSymbol.IsExtensionMethod)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
else if (symbolInfo.Symbol.Kind is SymbolKind.Property or SymbolKind.Method or SymbolKind.Field /*&& SymbolEqualityComparer.Default.Equals(symbolInfo.Symbol.ContainingType, _targetTypeSymbol)*/)
|
else if (symbolInfo.Symbol.Kind is SymbolKind.Property or SymbolKind.Method or SymbolKind.Field)
|
||||||
{
|
{
|
||||||
bool rewrite = true;
|
bool rewrite = true;
|
||||||
|
|
||||||
@@ -138,9 +138,13 @@ namespace EntityFrameworkCore.Projectables.Generator
|
|||||||
{
|
{
|
||||||
rewrite = false;
|
rewrite = false;
|
||||||
}
|
}
|
||||||
if (targetSymbolInfo.Symbol?.ContainingType is not null && !_context.Compilation.HasImplicitConversion(targetSymbolInfo.Symbol.ContainingType, _targetTypeSymbol))
|
if (targetSymbolInfo.Symbol?.ContainingType is not null)
|
||||||
{
|
{
|
||||||
rewrite = false;
|
if (!_context.Compilation.HasImplicitConversion(targetSymbolInfo.Symbol.ContainingType, _targetTypeSymbol) ||
|
||||||
|
!SymbolEqualityComparer.Default.Equals(symbolInfo.Symbol.ContainingType, _targetTypeSymbol))
|
||||||
|
{
|
||||||
|
rewrite = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (node.Parent.IsKind(SyntaxKind.SimpleAssignmentExpression))
|
else if (node.Parent.IsKind(SyntaxKind.SimpleAssignmentExpression))
|
||||||
|
|||||||
+18
@@ -0,0 +1,18 @@
|
|||||||
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using EntityFrameworkCore.Projectables;
|
||||||
|
using Foos;
|
||||||
|
|
||||||
|
namespace EntityFrameworkCore.Projectables.Generated
|
||||||
|
#nullable disable
|
||||||
|
{
|
||||||
|
public static class Foos_Bar_FooId
|
||||||
|
{
|
||||||
|
public static System.Linq.Expressions.Expression<System.Func<global::Foos.Bar, int>> Expression()
|
||||||
|
{
|
||||||
|
return (global::Foos.Bar @this) =>
|
||||||
|
@this.Foo.Id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+31
@@ -988,6 +988,37 @@ namespace Foo {
|
|||||||
return Verifier.Verify(result.GeneratedTrees[0].ToString());
|
return Verifier.Verify(result.GeneratedTrees[0].ToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public Task RelationalProperty()
|
||||||
|
{
|
||||||
|
var compilation = CreateCompilation(@"
|
||||||
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using EntityFrameworkCore.Projectables;
|
||||||
|
|
||||||
|
namespace Foos {
|
||||||
|
public class Foo {
|
||||||
|
public int Id { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Bar {
|
||||||
|
public Foo Foo { get; set; }
|
||||||
|
|
||||||
|
[Projectable]
|
||||||
|
public int FooId => Foo.Id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
");
|
||||||
|
|
||||||
|
var result = RunGenerator(compilation);
|
||||||
|
|
||||||
|
Assert.Empty(result.Diagnostics);
|
||||||
|
Assert.Single(result.GeneratedTrees);
|
||||||
|
|
||||||
|
return Verifier.Verify(result.GeneratedTrees[0].ToString());
|
||||||
|
}
|
||||||
|
|
||||||
#region Helpers
|
#region Helpers
|
||||||
|
|
||||||
Compilation CreateCompilation(string source, bool expectedToCompile = true)
|
Compilation CreateCompilation(string source, bool expectedToCompile = true)
|
||||||
|
|||||||
Reference in New Issue
Block a user