dotnet / dotnet/efcore

Stop sending parameters unnecessarily sent to server

Open
#35,579 0 comments 1 reaction 0 assignees View on GitHub
area-perf area-query
Dominant language
C#
Stars
14.8k
Forks
3.4k
PR merge metrics
PR metrics pending

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:

```csharp
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Diagnostics;

using (var db = new MyContext())
{
var listOfInt = new List { 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 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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.