mirror of
https://github.com/zoriya/EntityFrameworkCore.Projectables.git
synced 2026-08-15 18:44:57 +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());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user