# System.InvalidOperationException: The LINQ expression 'DbSet<X>.Where(x => x.Property.Contains("value") || x.OtherProperty.Contains("other"))' could not be translated. 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'.

- **ID:** `dotnet/ef-core-query-cannot-be-translated-into-a-sql-expression`
- **Domain:** dotnet
- **Category:** data_error
- **Verification:** ai_generated
- **Fix Rate:** 85%

## Root Cause

Entity Framework Core cannot translate a LINQ expression into SQL when it uses unsupported constructs like certain string methods, custom functions, or complex logic that the database provider does not support.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| Entity Framework Core 7.0 | active | — | — |
| Entity Framework Core 8.0 | active | — | — |
| Microsoft.EntityFrameworkCore.SqlServer 8.0.0 | active | — | — |

## Workarounds

1. **Rewrite the LINQ expression using only database-supported constructs. For example, replace 'x.Property.Contains("value") || x.OtherProperty.Contains("other")' with 'EF.Functions.Like(x.Property, "%value%") || EF.Functions.Like(x.OtherProperty, "%other%")' which translates to SQL LIKE.** (85% success)
   ```
   Rewrite the LINQ expression using only database-supported constructs. For example, replace 'x.Property.Contains("value") || x.OtherProperty.Contains("other")' with 'EF.Functions.Like(x.Property, "%value%") || EF.Functions.Like(x.OtherProperty, "%other%")' which translates to SQL LIKE.
   ```
2. **If the query cannot be rewritten, use client evaluation explicitly but filter as much as possible on the server side first. For example: 'var filtered = await context.Orders.Where(o => o.Status == "Active").ToListAsync(); var result = filtered.Where(o => o.Description.Contains("keyword")).ToList();'** (80% success)
   ```
   If the query cannot be rewritten, use client evaluation explicitly but filter as much as possible on the server side first. For example: 'var filtered = await context.Orders.Where(o => o.Status == "Active").ToListAsync(); var result = filtered.Where(o => o.Description.Contains("keyword")).ToList();'
   ```

## Dead Ends

- **** — Calling 'ToList()' before the filter forces client evaluation but loads all data into memory, causing performance issues and potential out-of-memory errors. (75% fail)
- **** — Adding 'AsEnumerable()' at the start of the query chain also forces full client evaluation, defeating the purpose of database filtering. (80% fail)
- **** — Ignoring the error and assuming the query works on a different database provider (e.g., SQLite vs SQL Server) leads to runtime failures when deploying. (90% fail)
