Hi,
I'm trying to map fields from two tables to a model but I keep getting the following error;
The entity or complex type cannot be constructed in a LINQ to Entities query.
Here is my code. Can anyone tell me what I'm doing wrong please?
[HttpGet, Authorize]
public ActionResult GetAssetTypeChecks(bool? isActive = null)
{
try
{
// List<AssetTypeCheck> assetTypeCheck = CompanyDatabase.AssetTypeChecks.AsNoTracking().OrderBy(x => x.Id).ToList();
List<AssetTypeCheck> assetTypeCheck = (from app in CompanyDatabase.AssetTypeChecks
join assettype in CompanyDatabase.AssetTypes on app.AssetTypeId equals assettype.Id
select new AssetTypeCheck
{
Id = app.Id,
Name = app.Name,
CheckType = app.CheckType,
Description = app.Description,
OrderNum = app.OrderNum
}).ToList();
return Json(new { success = true, result = assetTypeCheck }, JsonRequestBehavior.AllowGet);
}
catch (Exception exception)
{
return Json(new { success = false, message = exception.Message }, JsonRequestBehavior.AllowGet);
}
}