Open KillerBoogie opened 1 month ago
I found a way to get the desired result. Instead of creating a join I use a nested query. Below is just a fraction of the full query.
string prefLangs = string.Join(",", request.PreferedLanguages);
var eventQuery = dbContext.Event.AsNoTracking();
var eventVisibilityQuery = dbContext.EventVisibility.AsNoTracking();
var eventQuery = eventQuery.Where(e => request.Title.Equals(dbContext.GetLanguage(e.Title, prefLangs)!))
var query = eventQuery.Select(e => new EventDTO(
dbContext.GetLanguage(e.Title, @prefLangs)!,
eventVisibilityQuery.Where(v => v.Id == e.Visibility).Select(v => dbContext.GetLanguage(v.Name, prefLangs)!).First(),
)
This issue is lacking enough information for us to be able to fully understand what is happening. Please attach a small, runnable project or post a small, runnable code listing that reproduces what you are seeing so that we can investigate.
I have multi-language text that is stored as JSON in SQL Server fields. A user defined function
GetLanguage
returns the data from the JSON field in the preferred language. When returning data from one table only it works fine. When I create a join I'm getting the error that the LinQ can't be created.This works:
This causes runtime error as stated below:
Stack Trace:
For testing I tried to remove the
Where
clause and then got the error that Get`Language can't be called client side. I don't understand why this is happening.I have another query that uses query syntax and works fine:
I needed to use fluent syntax for the problematic query, because the
Where
clauses should be added dynamically depending on provided query parameters in the web API. Is this a problem with fluent syntax?Here is the EF Core configuration:
EF Core version: 8.0.7 Database provider: Microsoft.EntityFrameworkCore.SqlServer Target framework: NET 8.0 Operating system: Win 10 IDE: Visual Studio 2022 17.10.1