dotnet / dotnet/efcore

Investigate Hot Reload issues with EF Core

Open
#26,914 32 comments 21 reactions 0 assignees View on GitHub
area-global customer-reported
Dominant language
C#
Stars
14.8k
Forks
3.4k
PR merge metrics
PR metrics pending

Description

I've ported my project from v5 to v6 EF Core. Previously everything worked fine but now I'm getting random translation exceptions from `EF.Functions.Like` calls. I monitor the same operation and see the same data coming from input but sometimes it passes fine and sometimes throws an exception.

Behavior looks random, I can't understand what's causing it. But I see it is `a cascade failure`. Once one error pops, all queries with LIKE function starts to fail on execution: different tables, not a single one.

Call example:

```C#
public static async Task SetCacheLastAccess(string id, string type)
{
await using var db = new DbContext();
var entry = await db.Cache.FirstOrDefaultAsync(a => EF.Functions.Like(a.Id, id) && EF.Functions.Like(a.Type, type));
}

...
public string Type { get; set; } = "-";
public string Id { get; set; }
...
```

```
```
### Database
```C#
modelBuilder.Entity().HasIndex(u => u.Id);

modelBuilder.Entity().ToTable("cache");

modelBuilder.Entity().Property(a => a.Id).HasColumnName("id");
modelBuilder.Entity().Property(a => a.Type).HasColumnName("type");
modelBuilder.Entity().Property(a => a.LastAccess).HasColumnName("lastAccess");
modelBuilder.Entity().Property(a => a.LastUpdate).HasColumnName("lastUpdate");
modelBuilder.Entity().Property(a => a.Content).HasColumnName("text");
modelBuilder.Entity().Property(a => a.Days).HasColumnName("days");
```
![image](https://user-images.githubusercontent.com/5926603/144917096-9bd80490-ffaf-4d80-a7c6-5722f7767c77.png)

### Exception details

```
The LINQ expression 'DbSet()
.Where(t => __Functions_0
.Like(
matchExpression: t.Id,
pattern: __id_1) && __Functions_0
.Like(
matchExpression: t.Type,
pattern: __type_2))' could not be translated. Additional information: Translation of method 'Microsoft.EntityFrameworkCore.DbFunctionsExtensions.Like' failed. If this method can be mapped to your custom function, see https://go.microsoft.com/fwlink/?linkid=2132413 for more information.
Translation of method 'Microsoft.EntityFrameworkCore.DbFunctionsExtensions.Like' failed. If this method can be mapped to your custom function, see https://go.microsoft.com/fwlink/?linkid=2132413 for more information. Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly by inserting a call to 'AsEnumerable', 'AsAsyncEnumerable', 'ToList', or 'ToListAsync'. See https://go.microsoft.com/fwlink/?linkid=2101038 for more information.
```

```
at Microsoft.EntityFrameworkCore.Query.QueryableMethodTranslatingExpressionVisitor.g__CheckTranslated|15_0(ShapedQueryExpression translated, <>c__DisplayClass15_0& )
at Microsoft.EntityFrameworkCore.Query.QueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
at Microsoft.EntityFrameworkCore.Query.QueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
at Microsoft.EntityFrameworkCore.Query.QueryCompilationContext.CreateQueryExecutor[TResult](Expression query)
at Microsoft.EntityFrameworkCore.Storage.Database.CompileQuery[TResult](Expression query, Boolean async)
at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.CompileQueryCore[TResult](IDatabase database, Expression query, IModel model, Boolean async)
at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.<>c__DisplayClass12_0`1.b__0()
at Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddQuery[TResult](Object cacheKey, Func`1 compiler)
at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.ExecuteAsync[TResult](Expression query, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryProvider.ExecuteAsync[TResult](Expression expression, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ExecuteAsync[TSource,TResult](MethodInfo operatorMethodInfo, IQueryable`1 source, Expression expression, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ExecuteAsync[TSource,TResult](MethodInfo operatorMethodInfo, IQueryable`1 source, LambdaExpression expression, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.FirstOrDefaultAsync[TSource](IQueryable`1 source, Expression`1 predicate, CancellationToken cancellationToken)
at ThunderED.DbHelper.d__35.MoveNext() in
```

### Include provider and version information

EF Core version: 6.0.0
Database provider: Microsoft.EntityFrameworkCore.Sqlite 6.0.0
Target framework: .NET 6.0
Operating system: WIn10 x64 21H1
IDE: Visual Studio 2022 17.0.2
Project: Blazor Server-Side

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.