-
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
WHERE ... IN ... for .Contains(.Convert()) expressions issue #8207
Comments
Putting in 1.1.2 since it might be a regression, but we should check against 1.1.0 RTM. |
@Remleo I was able to reproduce the issue in 1.1.1 and patch bits (1.1.2), and you are right - it is due to the convert not being removed when we try to translate the predicate. However, the scenario was also failing for me in 1.1.0-preview1 (and from looking at the 1.1.0-preview1 code, the relevant code looks the same). I used the following code as repro: class Program
{
static void Main(string[] args)
{
using (var ctx = new MyContext())
{
ctx.Database.EnsureDeleted();
ctx.Database.EnsureCreated();
}
using (var ctx = new MyContext())
{
var someIds = new int[] { 1, 2, 3 }; // Have some Ids from method's parameter for example
ctx.ProductCards.Where(
card => someIds.Contains((int)card.GroupId)).Load();
// Code 2
ctx.ProductCards.Where(
card => ctx.ProductGroups.Select(group => group.Id).Where(g => g > 7)
.Contains((int)card.GroupId)
).Load();
}
}
}
public class ProductCard
{
public virtual int Id { get; set; }
public virtual int? GroupId { get; set; }
public virtual ProductGroup Group { get; set; }
}
public class ProductGroup
{
public virtual int Id { get; set; }
}
public class MyContext : DbContext
{
public DbSet<ProductGroup> ProductGroups { get; set; }
public DbSet<ProductCard> ProductCards { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlServer(@"Server=.;Database=Repro8207;Trusted_Connection=True;MultipleActiveResultSets=True");
}
} Can you double check that the problem actually was not present in 1.1.0-preview (and therefore it is a regression)? And if so, could you provide us with the full code listing that you used? (or point out the differences between your project and the one I posted above). The issue has been fixed already in the current bits (see #6937). It's just a question whether it should be considered for 1.1.2 patch or not. |
@maumar Sorry, my mistake. You are right, the problem was really present in 1.1.0-preview too. |
Code to reproduce:
The Code 1 throws warning:
Microsoft.EntityFrameworkCore.Query.Internal.SqlServerQueryCompilationContextFactory:Warning: The LINQ expression 'Contains(Convert([card].GroupId))' could not be translated and will be evaluated locally.
But the Code 2 generates correct SQL (ignores .Convert()):
The problem is in convertation from
int?
toint
. The PK isint
, but the FK isint?
.I can use
.Cast<int?>
via extra local var, but it's an extra work for CPU and memory. LINQ to SQL compiler can simply ignore .Convert().In the EF Core 1.1.0-preview1-final works fine! This problem appeared in version 1.1.1.
The text was updated successfully, but these errors were encountered: