mirror of
https://github.com/zoriya/EntityFrameworkCore.Projectables.git
synced 2026-05-25 03:53:18 +00:00
Fix for projectable instance members returning complex types
This commit is contained in:
+16
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using EntityFrameworkCore.Projectables;
|
||||
using Foo;
|
||||
|
||||
namespace EntityFrameworkCore.Projectables.Generated
|
||||
#nullable disable
|
||||
{
|
||||
public static class Foo_C_Foo
|
||||
{
|
||||
public static System.Linq.Expressions.Expression<System.Func<global::Foo.C, int>> Expression()
|
||||
{
|
||||
return (global::Foo.C @this) =>
|
||||
@this.Bar;
|
||||
}
|
||||
}
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
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_Entity_Something
|
||||
{
|
||||
public static System.Linq.Expressions.Expression<System.Func<global::Foo.EntityExtensions.Entity, global::Foo.EntityExtensions.Entity>> Expression()
|
||||
{
|
||||
return (global::Foo.EntityExtensions.Entity entity) =>
|
||||
new Entity(entity.Id) {
|
||||
FullName = entity.FullName
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
+59
@@ -76,6 +76,30 @@ namespace Foo {
|
||||
return Verifier.Verify(result.GeneratedTrees[0].ToString());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public Task MinimalProjectableComputedProperty()
|
||||
{
|
||||
var compilation = CreateCompilation(@"
|
||||
using System;
|
||||
using EntityFrameworkCore.Projectables;
|
||||
namespace Foo {
|
||||
class C {
|
||||
public int Bar { get; set; }
|
||||
|
||||
[Projectable]
|
||||
public int Foo => Bar;
|
||||
}
|
||||
}
|
||||
");
|
||||
|
||||
var result = RunGenerator(compilation);
|
||||
|
||||
Assert.Empty(result.Diagnostics);
|
||||
Assert.Single(result.GeneratedTrees);
|
||||
|
||||
return Verifier.Verify(result.GeneratedTrees[0].ToString());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public Task SimpleProjectableComputedProperty()
|
||||
{
|
||||
@@ -900,6 +924,41 @@ namespace Foo {
|
||||
return Verifier.Verify(result.GeneratedTrees[0].ToString());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public Task MixPrimaryConstructorAndProperties()
|
||||
{
|
||||
var compilation = CreateCompilation(@"
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using EntityFrameworkCore.Projectables;
|
||||
|
||||
namespace Foo {
|
||||
public static class EntityExtensions
|
||||
{
|
||||
public record Entity(int Id)
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string? FullName { get; set; }
|
||||
|
||||
[Projectable]
|
||||
public static Entity Something(Entity entity)
|
||||
=> new Entity(entity.Id) {
|
||||
FullName = entity.FullName
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
");
|
||||
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user