Ravi 1001

Ravi 1001

  • NA
  • 42
  • 669

Custom Linq query for Entity Framework & ASP.NET MVC app

May 13 2020 2:42 AM
I have been working on an ASP.NET MVC app using Entity Framework. Also, it's my first time developing an ASP.NET MVC app. I have been struggling (close to a month of trying and googling) to write a linq query to display results in jQuery datatable for the below SQL query. It involves various left joins and some columns have null values. It would be great if someone could help me out on this. There are 3 databases as below
  1. Assets
  2. Category
  3. Term
SQL QUERY
  1. SELECT Asset.Name AS Name, Asset.Type AS Type, Asset.Parent_Asset AS "Parent Asset", Cat.Category AS Category, Cat.Parent_Category AS "Parent Category",  
  2. T.BUSINESS_TERM AS "Business Term",  
  3. T.SHORT_DESCRIPTION AS Description FROM (SELECT CH.DISPLAY AS Name, CH.TYPE AS Type, PA.DISPLAY AS Parent_Asset, CH.CATEGORY_INT_ID  
  4. FROM [Metadata].[dbo].[Asset] CH LEFT JOIN [Metadata].[dbo].[Asset] PA ON PA.PARENT_ASSET_ID = CH.ASSET_INT_ID) Asset  
  5. LEFT JOIN (SELECT CH.DISPLAY AS Category, PA.DISPLAY AS Parent_Category, CH.CATEGORY_INT_ID AS Category_Id  
  6. FROM [METADATA].[dbo].[Category] CH LEFT JOIN [METADATA].[dbo].[Category] PA ON PA.PARENT_CATEGORY_ID = CH.CATEGORY_INT_ID) Cat ON Asset.CATEGORY_INT_ID = Cat.Category_Id  
  7. LEFT JOIN [Metadata].[dbo].[Term] T ON T.CATEGORY_INT_ID = Cat.Category_Id  

Answers (1)