mirror of
https://github.com/zoriya/EntityFrameworkCore.Projectables.git
synced 2026-06-23 13:26:53 +00:00
Support for declaring projectables on generic classes
This commit is contained in:
+5
@@ -0,0 +1,5 @@
|
||||
DECLARE @__key_0 nvarchar(4000) = N'x';
|
||||
|
||||
SELECT [c].[Id]
|
||||
FROM [ConcreteEntity] AS [c]
|
||||
WHERE CONVERT(varchar(11), [c].[Id]) = @__key_0
|
||||
@@ -0,0 +1,43 @@
|
||||
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.Generics
|
||||
{
|
||||
[UsesVerify]
|
||||
public class GenericEntityTests
|
||||
{
|
||||
public abstract class BaseEntity<TSelf, TKey>
|
||||
where TSelf : BaseEntity<TSelf, TKey>
|
||||
{
|
||||
public TKey Id { get; set; } = default!;
|
||||
|
||||
[Projectable(NullConditionalRewriteSupport = NullConditionalRewriteSupport.Ignore)]
|
||||
public bool HasMatchingStringKeyConversion(string key)
|
||||
=> Id?.ToString() == key;
|
||||
}
|
||||
|
||||
public class ConcreteEntity : BaseEntity<ConcreteEntity, int>
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public Task HasMatchingStringKeyConversion_GetsTranslated()
|
||||
{
|
||||
using var context = new SampleDbContext<ConcreteEntity>();
|
||||
var key = "x";
|
||||
var query = context.Set<ConcreteEntity>()
|
||||
.Where(x => x.HasMatchingStringKeyConversion(key))
|
||||
.Select(x => x.Id);
|
||||
|
||||
return Verifier.Verify(query.ToQueryString());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user