/****** Script for SelectTopNRows command from SSMS ******/
SELECT
B.[LabId]
,[TrayNo]
,B.[BoxNo]
,B.[RackNo]
,M.id,M.Id
FROM [BV_OCM].[dbo].[TblBatch] B INNER JOIN [BV_OCM].[dbo].[MstRackBox] M ON B.RackNo = M.RackNo and B.[BoxNo]=M.[BoxNo] where B.Id=85
How to write linq query of the below sql query
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.

Jay PankhaniyaRank #798 · 2.9K reputationPosted Jun 6, 2023, 4:42 AM EDT
var query = from b in dbContext.TblBatch join m in dbContext.MstRackBox on new { b.RackNo, b.BoxNo } equals new { m.RackNo, m.BoxNo } where b.Id == 85 select new { b.LabId, b.TrayNo, b.BoxNo, b.RackNo, m.Id };In the above query, 'dbContext' represents your database context object. You can replace it with the appropriate instance from your code. The query performs an inner join between the TblBatch and MstRackBox tables based on the conditions B.RackNo = M.RackNo and B.BoxNo = M.BoxNo. It then filters the results based on B.Id = 85. Finally, it selects the desired columns (LabId, TrayNo, BoxNo, RackNo, and Id) from the joined result set.