New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some values in queries are not going through value converter #11347

cincuranet opened this Issue Mar 20, 2018 · 1 comment


None yet
2 participants

cincuranet commented Mar 20, 2018

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'


class FooBar
	public int Id { get; set; }
	public string FooBarBaz { get; set; }

class MyContext : DbContext
	protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)

		optionsBuilder.UseSqlServer(@"Server=(localdb)\mssqllocaldb;Integrated Security=true;database=test");

	protected override void OnModelCreating(ModelBuilder modelBuilder)

			.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


This comment has been minimized.


ajcvickers commented Mar 22, 2018

This is a known issue with converters which is due to:

  • Lack of inference of the store type and facets in some translations, such as the Contains function translation--tracked by #4978
  • Lack of support in the query pipeline for performing different SQL translations when converters are being used--tracked by #10434

We plan to add a warning in 2.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment