how to join a table in asp.netcore

Viewed 38

Here the way I join the table I want to implement it to asp.net core I don't know which is the correct way.

left join MasterHubxRangeTest mhr on hb.categoryid=mhr.hubxcatid and mhr.ItemStatus='Normal' and mhr.CountryCode='AUS' and mhr.ItemTitle = hb.ItemTitle

below line of code is how i tried to implement the same in asp.net core here im using Include() function i think this is wrong which function should i use. Here HubxDataItems, HubxDataCategory, MasterHubxRangeTest are tables. I'm trying to get the data by giving some cnditions. The issue is only MasterHubxRangeTest table condition that I gave

var dataItems = 
    (from item in _context.HubxDataItems.Where(c => c.PatientId == patientId && c.IsActive == true && c.IsDeleted == false)
    from category in _context.HubxDataCategory.Where(c => c.Id == item.CategoryId && c.IsActive == true && c.IsDeleted == false)
    from range in _context.MasterHubxRangeTest.Include(d => d.HubXCatID == item.CategoryId && d.ItemTitle == item.ItemTitle && d.ItemStatus == "Normal" && d.CountryCode == "AUS").Where(c => c.HubXCatID == item.CategoryId  && c.IsActive == true && c.IsDeleted == false)
    select new
    {
        CategoryId = item.CategoryId,
        ItemTitle = item.ItemTitle,
        ItemValue = item.ItemValue,
        ItemUnit = category.CategoryName.Trim().ToLower() == "notes" ? category.CategoryName : item.ItemUnit,
        DisplayOrder = category.DisplayOrder,
        IsActive = item.IsActive,
        IsDeleted = item.IsDeleted,
        CreatedDate = item.CreatedDate,
        CreatedBy = item.CreatedBy,
        UpdatedBy = item.UpdatedBy,
        UpdatedDate = item.UpdatedDate,
        PatientId = item.PatientId,
        CategoryName = category.CategoryName,
        NormalRange = range.ItemValue,
        ItemColor = range.ItemColor             
    }).AsEnumerable();

0 Answers
Related