Skip to content

Stop sending parameters unnecessarily sent to server #35579

Description

@cincuranet

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions