Open
Description
When we select some variable, currently that creates a parameter and the value is sent to server, even when not used. This means data is transferred back and forth for no reason. To make matters worse, when the projection contains i.e. object, we completely switch to client-eval, creating more confusion.
Example:
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Diagnostics;
using (var db = new MyContext())
{
var listOfInt = new List<int> { 1 };
var anObject = new { };
await db.Items.Select((e) => new { e.Id, listOfInt }).ToListAsync();
await db.Items.Select((e) => new { e.Id, listOfInt, anObject }).ToListAsync();
}
class MyContext : DbContext
{
public DbSet<Item> Items { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder
.UseSqlite("Data Source=triage.db")
.LogTo(Console.WriteLine, filter: (id, level) => id == RelationalEventId.CommandExecuting)
.EnableSensitiveDataLogging();
}
}
class Item
{
public int Id { get; set; }
public string? Name { get; set; }
}
The first query is SELECT "i"."Id", @__listOfInt_0 AS "listOfInt" FROM "Items" AS "i"
. The other is SELECT "i"."Id" FROM "Items" AS "i"
.
Related to #35580.