-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Use column/property facets for parameter types in Query Pipeline #4608
Comments
Try:
|
Hi, Thanks, tested but unfortunately same query is generated: modelBuilder.Entity<Products>(entity =>
{
entity.ToTable("Products", "ofr");
entity.HasIndex(e => e.ProductId).HasName("IX_Products_ProductId").IsUnique();
entity.HasIndex(e => new { e.Id, e.ProductId, e.PublicationId }).HasName("IX_ofr_Products_PublicationId");
entity.Property(e => e.ProductId)
.IsRequired()
.HasMaxLength(50)
.HasColumnType("VARCHAR(50)");
}); exec sp_executesql N'SELECT [p].[Id], [p].[ProductId], [p].[PublicationId]
FROM [ofr].[Products] AS [p]
INNER JOIN [ofr].[SiteProducts] AS [sp] ON ([p].[Id] = [sp].[ProdId]) AND ([p].[ProductId] = @__req_ProductId_0)
WHERE [sp].[SiteId] = @__req_Engine_Context_SiteId_1',N'@__req_ProductId_0 nvarchar(4000),@__req_Engine_Context_SiteId_1 int',@__req_ProductId_0=N'350003995',@__req_Engine_Context_SiteId_1=1 For reference I'm running this from a DNX project, my project.json file: {
"version": "1.0.0-*",
"description": "...",
"authors": [ "..." ],
"tags": [ "" ],
"projectUrl": "",
"licenseUrl": "",
"frameworks": {
"dnx451": {
"dependencies": {
"Microsoft.CSharp": "4.0.1-beta-23516",
"System.Collections": "4.0.11-beta-23516",
"System.Linq": "4.0.1-beta-23516",
"System.Runtime": "4.0.21-beta-23516",
"System.Threading": "4.0.11-beta-23516"
}
}
},
"dependencies": {
"EntityFramework.Commands": "7.0.0-rc1-final",
"EntityFramework.MicrosoftSqlServer": "7.0.0-rc1-final",
"EntityFramework.MicrosoftSqlServer.Design": "7.0.0-rc1-final",
"EntityFramework.Core": "7.0.0-rc1-final",
"Microsoft.Extensions.Logging": "1.0.0-rc1-final",
"Microsoft.Extensions.Logging.Abstractions": "1.0.0-rc1-final",
"Microsoft.Extensions.DependencyInjection.Abstractions": "1.0.0-rc1-final",
"Microsoft.Extensions.DependencyInjection": "1.0.0-rc1-final"
},
"commands": {
"ef": "EntityFramework.Commands"
}
}
|
Probably considered a duplicate of #4134 and missing the index would be a good reason to do that work sooner rather than later. |
Thanks for the feedback. Just to add one further detail in case it helps: this is only impacting queries which compare VARCHAR columns to string variables. The following query compares a VARCHAR column to an explicit string value "12345" var q = from p in products
join sp in dbContext.SiteProducts
on new { Id = p.Id, ProductId = p.ProductId }
equals new { Id = sp.ProdId, ProductId = "12345"}
where sp.SiteId == req.Engine.Context.SiteId
select p; The comparison at SQL level is fine, "12345" is not presented as N'12345" and therefore utilises indexes on the VARCHAR column correctly: exec sp_executesql N'SELECT [p].[Id], [p].[ProductId], [p].[PublicationId]
FROM [ofr].[Products] AS [p]
INNER JOIN [ofr].[SiteProducts] AS [sp] ON ([p].[Id] = [sp].[ProdId]) AND ([p].[ProductId] = ''12345'')
WHERE [sp].[SiteId] = @__req_Engine_Context_SiteId_0',N'@__req_Engine_Context_SiteId_0 int',@__req_Engine_Context_SiteId_0=1 |
Once facets for parameter types have been added to the query pipeline, we should ensure the |
Issues: #4608 Use column/property facets for parameter types in Query Pipeline #4134 Use column/property facets for parameter types in Update Pipeline If a property length is specified, then this is used to infer the length to use for parameters relating to that property, unless the length of the data is too long, in which case unbounded length is used. Because query has code that can infer the length to use for a parameter this still means that fragmentation will not happen without always using the 4000/8000 value.
Issues: #4608 Use column/property facets for parameter types in Query Pipeline #4134 Use column/property facets for parameter types in Update Pipeline If a property length is specified, then this is used to infer the length to use for parameters relating to that property, unless the length of the data is too long, in which case unbounded length is used. Because query has code that can infer the length to use for a parameter this still means that fragmentation will not happen without always using the 4000/8000 value.
Issues: #4608 Use column/property facets for parameter types in Query Pipeline #4134 Use column/property facets for parameter types in Update Pipeline If a property length is specified, then this is used to infer the length to use for parameters relating to that property, unless the length of the data is too long, in which case unbounded length is used. Because query has code that can infer the length to use for a parameter this still means that fragmentation will not happen without always using the 4000/8000 value.
Unless I'm missing something, parameterised queries (against SQL Server in my case) are treating all strings as NVARCHAR
I have the below table definition:
Then a query:
The query generated is:
The "ProductId" parameter is therefore treated as an NVARCHAR, obviously missing the index.
I have tested with EF6 against the same database, and the query generated correctly uses a VARCHAR parameter:
Is this something which is in-line to be fixed, or is there perhaps a workaround?
Thanks
The text was updated successfully, but these errors were encountered: