dotnet / dotnet/efcore

Code for precompiled query with .AsNoTracking() has variable name with dots in it

Open
#37,972 1 comment 0 reactions 0 assignees View on GitHub
area-precompiled-queries customer-reported
Dominant language
C#
Stars
14.8k
Forks
3.4k
PR merge metrics
PR metrics pending

Description

### Bug description

Precompiling query with `.AsNoTracking()` generates code that has an incorrect variable name with dots included:

```
var extradots.BlogPrimaryKeyProperties = blogEntityType.FindPrimaryKey().Properties;
```

Compilation then fails with errors:

```
/workspaces/ef-play/extradots/Generated/Program.EFInterceptors.Context.cs(63,26): error CS1003: Syntax error, ',' expected
/workspaces/ef-play/extradots/Generated/Program.EFInterceptors.Context.cs(63,27): error CS1002: ; expected
```

Problem goes away if there is a `.Select()` in the query.

See attached project with minimal example.

Can be reproduced with:

```
> dotnet publish --ucr --sc
```

[extradots.zip](https://github.com/user-attachments/files/26183723/extradots.zip)

### Your code

```csharp
--- Model.cs

namespace extradots;

public class Blog
{
public int Id { get; set; }
}

--- Context.cs

using Microsoft.EntityFrameworkCore;

namespace extradots;

public class Context : DbContext
{
public DbSet Blogs { get; set; } = null!;

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
base.OnConfiguring(optionsBuilder);
optionsBuilder.UseSqlite("Data Source=tmp.db");
}
}

--- Program.cs

using Microsoft.EntityFrameworkCore;
using extradots;

using var context = new Context();

_ = context.Blogs
.AsNoTracking()
// .Select(b => b.Id)
.ToList();
```

### Stack traces

```text

```

### Verbose output

```text

```

### EF Core version

10.0.3, 11.0.0-preview.2.26159.112

### Database provider

Microsoft.EntityFrameworkCore.Sqlite

### Target framework

.NET 10, .NET 11

### Operating system

Ubuntu 24.04.4 LTS

### IDE

_No response_

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.