following query showing incorrect syntax near the keyword 'with'. if this statement is a common table expression. when using contains in linq after update .net 6.0 to 8.0
var query = from entity in dbContext.YourEntity
where entity.SomeProperty.Contains(someValue)
select entity;
Jithu ThomasPosted Apr 4, 2024, 6:45 AM
You're absolutely right. There's a known breaking change in Entity Framework Core (EF Core) 8.0 that affects LINQ queries using
Containswith older SQL Server versions. Here's the breakdown:The Issue:
Containsis translated to SQL for older SQL Servers (pre-2016) has changed.Affected Scenarios:
Containsto filter entities.The Code Snippet:
Solutions:
Alternative Approaches (if compatibility changes are not preferred):
Containslogic using a different SQL expression supported by your older SQL Server version (e.g.,LIKE).Choosing the Right Solution:
The best approach depends on your specific circumstances. Upgrading SQL Server is generally recommended for long-term performance and functionality benefits. If upgrading isn't feasible, consider setting the compatibility level cautiously, with an understanding of potential trade-offs.
Remember to test your application thoroughly after making any changes to ensure everything works as expected.
Sam HobbsPosted Apr 3, 2024, 10:35 PM
I do not see with anywhere in the code you show.