mirror of
https://github.com/zoriya/EntityFrameworkCore.Projectables.git
synced 2026-06-12 10:07:56 +00:00
Support for const and static in projectables
This commit is contained in:
+3
@@ -0,0 +1,3 @@
|
||||
SELECT [e].[Id], [e].[Price]
|
||||
FROM [Entity] AS [e]
|
||||
WHERE [e].[Price] > 1.0E0
|
||||
@@ -0,0 +1,45 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.SqlTypes;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using EntityFrameworkCore.Projectables.Extensions;
|
||||
using EntityFrameworkCore.Projectables.FunctionalTests.Helpers;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using ScenarioTests;
|
||||
using VerifyXunit;
|
||||
using Xunit;
|
||||
|
||||
namespace EntityFrameworkCore.Projectables.FunctionalTests
|
||||
{
|
||||
[UsesVerify]
|
||||
public class StaticMembersTests
|
||||
{
|
||||
public static class Constants
|
||||
{
|
||||
public static readonly double ExpensiveThreshold = 1;
|
||||
}
|
||||
|
||||
public record Entity
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
public double Price { get; set; }
|
||||
|
||||
[Projectable]
|
||||
public bool IsExpensive => Price > Constants.ExpensiveThreshold;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public Task FilterOnProjectableProperty()
|
||||
{
|
||||
using var dbContext = new SampleDbContext<Entity>(Infrastructure.CompatibilityMode.Full);
|
||||
|
||||
var query = dbContext.Set<Entity>()
|
||||
.Where(x => x.IsExpensive);
|
||||
|
||||
return Verifier.Verify(query.ToQueryString());
|
||||
}
|
||||
}
|
||||
}
|
||||
+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_Foo_IdWithBar
|
||||
{
|
||||
public static System.Linq.Expressions.Expression<System.Func<global::Foo.Foo, int>> Expression()
|
||||
{
|
||||
return (global::Foo.Foo @this) =>
|
||||
@this.Id + global::Foo.Foo.Bar;
|
||||
}
|
||||
}
|
||||
}
|
||||
+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_Foo_IdWithBar
|
||||
{
|
||||
public static System.Linq.Expressions.Expression<System.Func<global::Foo.Foo, int>> Expression()
|
||||
{
|
||||
return (global::Foo.Foo @this) =>
|
||||
@this.Id + global::Foo.Constants.Bar;
|
||||
}
|
||||
}
|
||||
}
|
||||
+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_Foo_IdWithBar
|
||||
{
|
||||
public static System.Linq.Expressions.Expression<System.Func<global::Foo.Foo, int>> Expression()
|
||||
{
|
||||
return (global::Foo.Foo @this) =>
|
||||
@this.Id + global::Foo.Foo.Bar;
|
||||
}
|
||||
}
|
||||
}
|
||||
+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_Foo_IdWithBar
|
||||
{
|
||||
public static System.Linq.Expressions.Expression<System.Func<global::Foo.Foo, int>> Expression()
|
||||
{
|
||||
return (global::Foo.Foo @this) =>
|
||||
@this.Id + @this.Bar;
|
||||
}
|
||||
}
|
||||
}
|
||||
+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_Foo_IdWithBar
|
||||
{
|
||||
public static System.Linq.Expressions.Expression<System.Func<global::Foo.Foo, bool>> Expression()
|
||||
{
|
||||
return (global::Foo.Foo @this) =>
|
||||
@this.Id > global::Foo.Constants.Bar;
|
||||
}
|
||||
}
|
||||
}
|
||||
+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_Foo_IdWithBar
|
||||
{
|
||||
public static System.Linq.Expressions.Expression<System.Func<global::Foo.Foo, int>> Expression()
|
||||
{
|
||||
return (global::Foo.Foo @this) =>
|
||||
@this.Id + global::Foo.Constants.Bar;
|
||||
}
|
||||
}
|
||||
}
|
||||
+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_Foo_IdWithBar
|
||||
{
|
||||
public static System.Linq.Expressions.Expression<System.Func<global::Foo.Foo, int>> Expression()
|
||||
{
|
||||
return (global::Foo.Foo @this) =>
|
||||
@this.Id + @this.Bar;
|
||||
}
|
||||
}
|
||||
}
|
||||
+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_Foo_IdWithBar
|
||||
{
|
||||
public static System.Linq.Expressions.Expression<System.Func<global::Foo.Foo, int>> Expression()
|
||||
{
|
||||
return (global::Foo.Foo @this) =>
|
||||
@this.Id + global::Foo.Foo.Bar;
|
||||
}
|
||||
}
|
||||
}
|
||||
+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_Foo_IdWithBar
|
||||
{
|
||||
public static System.Linq.Expressions.Expression<System.Func<global::Foo.Foo, int>> Expression()
|
||||
{
|
||||
return (global::Foo.Foo @this) =>
|
||||
@this.Id + global::Foo.Constants.Bar;
|
||||
}
|
||||
}
|
||||
}
|
||||
+149
@@ -988,6 +988,155 @@ namespace Foo {
|
||||
return Verifier.Verify(result.GeneratedTrees[0].ToString());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public Task StaticMembers()
|
||||
{
|
||||
var compilation = CreateCompilation(@"
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using EntityFrameworkCore.Projectables;
|
||||
|
||||
namespace Foo {
|
||||
public class Foo {
|
||||
public static int Bar { get; set; }
|
||||
|
||||
public int Id { get; set; }
|
||||
|
||||
[Projectable]
|
||||
public int IdWithBar() => Id + Bar;
|
||||
}
|
||||
}
|
||||
");
|
||||
|
||||
var result = RunGenerator(compilation);
|
||||
|
||||
Assert.Empty(result.Diagnostics);
|
||||
Assert.Single(result.GeneratedTrees);
|
||||
|
||||
return Verifier.Verify(result.GeneratedTrees[0].ToString());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public Task StaticMembers2()
|
||||
{
|
||||
var compilation = CreateCompilation(@"
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using EntityFrameworkCore.Projectables;
|
||||
|
||||
namespace Foo {
|
||||
public static class Constants {
|
||||
public static readonly int Bar = 1;
|
||||
}
|
||||
|
||||
public class Foo {
|
||||
public int Id { get; set; }
|
||||
|
||||
[Projectable]
|
||||
public int IdWithBar() => Id + Constants.Bar;
|
||||
}
|
||||
}
|
||||
");
|
||||
|
||||
var result = RunGenerator(compilation);
|
||||
|
||||
Assert.Empty(result.Diagnostics);
|
||||
Assert.Single(result.GeneratedTrees);
|
||||
|
||||
return Verifier.Verify(result.GeneratedTrees[0].ToString());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public Task ConstMember()
|
||||
{
|
||||
var compilation = CreateCompilation(@"
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using EntityFrameworkCore.Projectables;
|
||||
|
||||
namespace Foo {
|
||||
public class Foo {
|
||||
public const int Bar = 1;
|
||||
|
||||
public int Id { get; set; }
|
||||
|
||||
[Projectable]
|
||||
public int IdWithBar() => Id + Bar;
|
||||
}
|
||||
}
|
||||
");
|
||||
|
||||
var result = RunGenerator(compilation);
|
||||
|
||||
Assert.Empty(result.Diagnostics);
|
||||
Assert.Single(result.GeneratedTrees);
|
||||
|
||||
return Verifier.Verify(result.GeneratedTrees[0].ToString());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public Task ConstMember2()
|
||||
{
|
||||
var compilation = CreateCompilation(@"
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using EntityFrameworkCore.Projectables;
|
||||
|
||||
namespace Foo {
|
||||
public static class Constants {
|
||||
public const int Bar = 1;
|
||||
}
|
||||
|
||||
public class Foo {
|
||||
public int Id { get; set; }
|
||||
|
||||
[Projectable]
|
||||
public int IdWithBar() => Id + Constants.Bar;
|
||||
}
|
||||
}
|
||||
");
|
||||
|
||||
var result = RunGenerator(compilation);
|
||||
|
||||
Assert.Empty(result.Diagnostics);
|
||||
Assert.Single(result.GeneratedTrees);
|
||||
|
||||
return Verifier.Verify(result.GeneratedTrees[0].ToString());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public Task ConstMember3()
|
||||
{
|
||||
var compilation = CreateCompilation(@"
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using EntityFrameworkCore.Projectables;
|
||||
|
||||
namespace Foo {
|
||||
public class Foo {
|
||||
public const int Bar = 1;
|
||||
|
||||
public int Id { get; set; }
|
||||
|
||||
[Projectable]
|
||||
public int IdWithBar() => Id + Foo.Bar;
|
||||
}
|
||||
}
|
||||
");
|
||||
|
||||
var result = RunGenerator(compilation);
|
||||
|
||||
Assert.Empty(result.Diagnostics);
|
||||
Assert.Single(result.GeneratedTrees);
|
||||
|
||||
return Verifier.Verify(result.GeneratedTrees[0].ToString());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public Task RelationalProperty()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user