mirror of
https://github.com/zoriya/EntityFrameworkCore.Projectables.git
synced 2026-05-25 12:03:20 +00:00
Merge pull request #11 from koenbeuk/issue-10
Support Inherited properties
This commit is contained in:
+2
@@ -0,0 +1,2 @@
|
||||
SELECT CAST([c].[Age] AS float) / [c].[AverageLifespan] AS [LifeProgression], CAST([c].[MentalAge] AS float) / [c].[AverageLifespan] AS [MentalLifeProgression]
|
||||
FROM [Cat] AS [c]
|
||||
@@ -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
|
||||
{
|
||||
[UsesVerify]
|
||||
public class InheritedMembersTests
|
||||
{
|
||||
public abstract class Animal
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public double AverageLifespan { get; set; }
|
||||
public int Age { get; set; }
|
||||
|
||||
[Projectable]
|
||||
public double LifeProgression
|
||||
=> Age / AverageLifespan;
|
||||
}
|
||||
|
||||
public class Cat : Animal
|
||||
{
|
||||
public int MentalAge { get; set; }
|
||||
|
||||
[Projectable]
|
||||
public double MentalLifeProgression
|
||||
=> MentalAge / AverageLifespan;
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public Task ProjectOverMethodTakingDbContext()
|
||||
{
|
||||
using var dbContext = new SampleDbContext<Cat>();
|
||||
|
||||
var query = dbContext.Set<Cat>()
|
||||
.Select(x => new { x.LifeProgression, x.MentalLifeProgression });
|
||||
|
||||
return Verifier.Verify(query.ToQueryString());
|
||||
}
|
||||
}
|
||||
}
|
||||
-5
@@ -23,11 +23,6 @@
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Remove="**\*.verified.txt" />
|
||||
<None Remove="**\*.received.txt" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\EntityFrameworkCore.Projectables.Generator\EntityFrameworkCore.Projectables.Generator.csproj" />
|
||||
<ProjectReference Include="..\..\src\EntityFrameworkCore.Projectables\EntityFrameworkCore.Projectables.csproj" />
|
||||
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using EntityFrameworkCore.Projectables;
|
||||
using Foo;
|
||||
|
||||
namespace EntityFrameworkCore.Projectables.Generated
|
||||
#nullable disable
|
||||
{
|
||||
public static class Foo_Bar_ProjectedId
|
||||
{
|
||||
public static System.Linq.Expressions.Expression<System.Func<global::Foo.Bar, int>> Expression()
|
||||
{
|
||||
return (global::Foo.Bar @this) =>
|
||||
@this.Id;
|
||||
}
|
||||
}
|
||||
}
|
||||
+29
@@ -959,6 +959,35 @@ namespace Foo {
|
||||
return Verifier.Verify(result.GeneratedTrees[0].ToString());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public Task InheritedMembers()
|
||||
{
|
||||
var compilation = CreateCompilation(@"
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using EntityFrameworkCore.Projectables;
|
||||
|
||||
namespace Foo {
|
||||
public class Foo {
|
||||
public int Id { get; set; }
|
||||
}
|
||||
|
||||
public class Bar : Foo {
|
||||
[Projectable]
|
||||
public int ProjectedId => Id;
|
||||
}
|
||||
}
|
||||
");
|
||||
|
||||
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