Skip to content

Support .NET 10 span overloads #1295

Description

@StephenCleary

When targeting .NET 10 (with C# 14), the compiler overload resolution rules changed (other docs), which breaks some usage of Contains and friends.

Example issue

Given the code:

string[] names = ["a", "b", "c"];
connection.Table<MyType>.Where(t => names.Contains(t.Name))

the Contains previously would resolve to Enumerable.Contains(names, t.Name), which was handled here. However, in .NET 10 (actually, C# 14), the Contains resolves to MemoryExtensions.Contains((ReadOnlySpan<MyType>)names, t.Name).

This results in SQL generated like select * from \"MyType\" where (\"Name\" in op_implicit((?,?))), which results in an exception like SQLite.SQLiteException: no such table: op_implicit.

EF Core had to change to support this, too

See similar issues for Expression tree handling in EFCore:

Recommended solution

Update TableQuery<T>.CompileExpr to:

  • Detect MemoryExtensions.Contains (both the 2-argument and 3-argument versions if the 3rd argument is null), and treat it as though it were Enumerable.Contains, in particular unwrapping and ignoring the implicit cast.
  • Consider whether to do the same for MemoryExtensions.SequenceEqual.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions