Closed as not planned
Description
With the setup below the query db.Set<FooBar>().Where(x => x.FooBarBaz.Contains("test")).Load()
is translated to:
SELECT [x].[Id], [x].[FooBarBaz]
FROM [FooBar] AS [x]
WHERE CHARINDEX(N'test', [x].[FooBarBaz]) > 0
The test
didn't went through the converter. Similarly db.Set<FooBar>().Where(x => x.FooBarBaz.StartsWith("test")).Load()
and db.Set<FooBar>().Where(x => x.FooBarBaz.EndsWith("test")).Load()
respectively result in following SQL where the LEN
is not not transformed:
SELECT [x].[Id], [x].[FooBarBaz]
FROM [FooBar] AS [x]
WHERE [x].[FooBarBaz] LIKE N'ToStoreExpr' + N'ToStoreExpr' AND (LEFT([x].[FooBarBaz], LEN(N'test')) = N'ToStoreExpr')
SELECT [x].[Id], [x].[FooBarBaz]
FROM [FooBar] AS [x]
WHERE RIGHT([x].[FooBarBaz], LEN(N'test')) = N'ToStoreExpr'
Setup
class FooBar
{
public int Id { get; set; }
public string FooBarBaz { get; set; }
}
class MyContext : DbContext
{
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
base.OnConfiguring(optionsBuilder);
optionsBuilder.UseSqlServer(@"Server=(localdb)\mssqllocaldb;Integrated Security=true;database=test");
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<FooBar>()
.Property(x => x.FooBarBaz)
.HasConversion(new DummyConverter());
}
}
class DummyConverter : ValueConverter<string, string>
{
public DummyConverter(ConverterMappingHints mappingHints = default)
: base(ToStoreExpr, FromStoreExpr, mappingHints)
{ }
static Expression<Func<string, string>> FromStoreExpr = _ => nameof(FromStoreExpr);
static Expression<Func<string, string>> ToStoreExpr = _ => nameof(ToStoreExpr);
}
Further technical details
EF Core version: 2.1.0-preview1-final
Database Provider: Microsoft.EntityFrameworkCore.SqlServer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment