efcore icon indicating copy to clipboard operation
efcore copied to clipboard

Queries on non unicode string column should not prefix strings with N

Open rmja opened this issue 10 years ago • 6 comments

Steps to reproduce

If a column is configured with a non n* string type, say char(3), then the SQL builder should not prefix strings in the generated SQL with a N. For example:

builder.Property<string>("Discriminator").IsRequired().HasColumnType("char(3)");

results in:

...WHERE ([x].[Discriminator] IN (N''obj'', N''int'', N''dbl'', N''dec'')

Running that query in SMSS returns the execution plan warning:

Type conversion in expression (CONVERT_IMPLICIT(nchar(3),[Table].[Discriminator],0)=N'obj') may affect "SeekPlan" in query plan choice

Removing the N string prefix removes the warning.

I have performed some non scientific experiments on a query and here are some results (elapsed time in ms): Without N With N 557 536 515 581 495 562 494 585 536 500 529 582 510 502 525 590 518 531 511 622 Average 519 559,1

So by removing the N prefix, the query actually runs faster

Further technical details

EF Core version: 1.0.0

rmja avatar Nov 08 '16 05:11 rmja

Did you try this with 1.1 preview 1

ErikEJ avatar Nov 08 '16 07:11 ErikEJ

@ErikEJ Nope, I am not running on those bits yet.

rmja avatar Nov 08 '16 08:11 rmja

This should be fixed in 1.1. You can try out preview1 which includes the fix.

rowanmiller avatar Nov 09 '16 19:11 rowanmiller

in EF Core 2.0 still happening this issue

fchiumeo avatar Aug 25 '17 19:08 fchiumeo

@fchiumeo - Please file a new issue with the query in which you are seeing this error.

smitpatel avatar Aug 25 '17 19:08 smitpatel

@smitpatel done #9582

fchiumeo avatar Aug 25 '17 19:08 fchiumeo