We are using a .NET Core application (meanwhile running on localhost) and a SQL database running on SQL Server where we receive data from. In the following method which is called inside the controller we are using Entity Framework Core to query the data in SQL database:
public ActionResult InspectionDetails(string inspectionId, string lang)
{
// load all checks for an inspection
var inspectionChecks = (from ic in _context.InspectedChecks.Where(x => x.InspectionId.ToString() == inspectionId)
from cp in _context.CheckPoints.Where(x => x.CategoryId == ic.CategoryId && x.CheckId == ic.CheckId)
from tChecks in _context.Translations.Where(x => x.TranslationKey == cp.Title && x.Lang.ToLower() == lang.ToLower()).DefaultIfEmpty()
from tChecksFallBack in _context.Translations.Where(x => x.TranslationKey == cp.Title && x.Lang.ToLower() == "en").DefaultIfEmpty()
select new InspectedChecks2
{
Id = ic.Id,
CheckDate = ic.CheckDate,
Category = ic.CategoryId.ToString(),
Check = tChecks.TextValue ?? tChecksFallBack.TextValue,
CheckingUser = ic.CheckingUser,
Result = ic.Result,
Passed = ic.Passed,
InspectionId = ic.InspectionId,
ToleranceValue = ic.ToleranceValue,
Images = null,
Unit = ic.Unit
}).ToList();
return Content(JsonConvert.SerializeObject(inspectionChecks));
}
if the InspectionDetails method is called the following exception is thrown:
System.Data.SqlClient.SqlException: "The multi-part identifier "x0.title" could not be bound. The multi-part identifier "x0.title" could not be bound."
Further infromation: "cp" contains the disired values, so everything works fine till there.
What we tried so far:
- Run the same query directly on the SQL database --> Success
- Run two querys in the InspectionDetails method (first query: set a var to the value of "cp", second query: like above, except using with the new var insted of "cp") --> NO Success
Anyone who had a similar issue or knows how to fix it?
Thanks in Advance