You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Here is what to include in your request to make sure we implement a solution as quickly as possible.
1. Description
When using an Npgsql-based database context, running a batch update query on a collection filtered through a SelectListIterator throws a System.InvalidCastException
Example code:
class Model
{
public int Id { get; set; }
public string Foo { get; set; }
}
class DatabaseContext : DbContext
{
public DbSet<Model> Models { get; set; }
public DatabaseContext(DbContextOptions options) : base(options) { }
}
class Program
{
public static void Main(string[] args)
{
using var context = new DbContext(new DbContextOptionsBuilder<DatabaseContext>().UseNpgsql("<ConnectionString>").Options);
context.Models.Add(new Model() { Id = 1, Foo = "foo" });
context.SaveChanges();
var idList = new List<int>() { 1 }
// Doesn't have a real purpose of course, but for example's sake. The point is that idsToUpdate is a SelectListIterator
var idsToUpdate = idList.Select(x => x);
// Throws InvalidCastException
context.Models.Where(x => idsToUpdate.Contains(x.Id)).Update(x => new() { Foo = "bar" });
}
}
When changing .Where(x => idsToUpdate.Contains(x.Id)) to .Where(x => idList.Contains(x.Id)) it does work
When using another provider (tested with InMemory and Sqlite) it does work
2. Exception
If you are seeing an exception, include the full exception details (message and stack trace).
Exception message:
System.InvalidCastException : Unable to cast object of type 'SelectListIterator`2[System.Int32, System.Int32]' to type 'System.Collections.Generic.IList`1[System.Int32]'.
Stack trace:
lambda_method469(Closure, IEnumerable`1)
<>c__DisplayClass6_0`2.<SanitizeConverter>b__1(Object v)
RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
MethodBaseInvoker.InvokeDirectByRefWithFewArgs(Object obj, Span`1 copyOfArgs, BindingFlags invokeAttr)
3. Fiddle or Project
See example code above
4. Any further technical details
This was working fine in version 6.100.0.5 but is broken in the latest version
Further technical details
EF version: [EF Core v8.0.7]
EF Plus version: [EF Plus Core v8.103.0]
Database Server version: [PostgreSQL 14]
Database Provider version (NuGet): [Npgsql.EntityFrameworkCore.PostgreSQL v8.0.4]
The text was updated successfully, but these errors were encountered:
Here is what to include in your request to make sure we implement a solution as quickly as possible.
1. Description
When using an Npgsql-based database context, running a batch update query on a collection filtered through a
SelectListIterator
throws aSystem.InvalidCastException
Example code:
When changing
.Where(x => idsToUpdate.Contains(x.Id))
to.Where(x => idList.Contains(x.Id))
it does workWhen using another provider (tested with InMemory and Sqlite) it does work
2. Exception
If you are seeing an exception, include the full exception details (message and stack trace).
3. Fiddle or Project
See example code above
4. Any further technical details
This was working fine in version 6.100.0.5 but is broken in the latest version
Further technical details
The text was updated successfully, but these errors were encountered: