Sandeep Kumar

Sandeep Kumar

  • 1k
  • 627
  • 50.4k

how to write linq query of the below sql query

Jul 14 2023 11:53 AM

select ROW_NUMBER() over (order by m.Id) RowNumber,
        ROW_NUMBER() over (partition by m.Rack order by m.Id) Rankvendor,
        m.Id,
        m.Rack,
        m.Capacity,
        s.BatchId,
        s.SampleQty
        
 from [MstStorage]  M LEFT JOIN [tblStorageBatch] S ON M.Id=S.StorageId

---------------My Linq Code------------------------

 List<TestRetensionList> _TestRetensionList = new List<TestRetensionList>();
            try
            {
                _TestRetensionList = (from MstStorage in _dbContext.MstStorage.Where(k => k.IsActive == ApplicationData.IsActive)
                                      join TblStorageBatch in _dbContext.TblStorageBatch on MstStorage.Id equals TblStorageBatch.StorageId into TblStorageBatch
                                      from m1 in TblStorageBatch.DefaultIfEmpty()
                                     
                                      select new
                                      {
                                          Id = MstStorage.Id,
                                          Row = MstStorage.Row,
                                          Shelf = MstStorage.Shelf,
                                          Tray = MstStorage.Tray,
                                          Capacity = MstStorage.Capacity,
                                          LabId = MstStorage.LabId,
                                          BatchId = m1.BatchId,
                                          SampleQty = m1.SampleQty,
                                          Rack = MstStorage.Rack
                                        
                                      }).AsEnumerable().Select((k, index) => new TestRetensionList()
                                      {

                                          Id = k.Id,
                                          Row = k.Row,
                                          Shelf = k.Shelf,
                                          Tray = k.Tray,
                                          Capacity = k.Capacity,
                                          LabId = k.LabId,
                                          BatchId = k.BatchId,
                                          SampleQty = k.SampleQty,
                                          Rack = k.Rack,
                                          LeftQty = (k.Capacity - k.SampleQty),

                                           Rank=  ??

                                          Statuscolor = Statuscolor((int)(k.Capacity - k.SampleQty), k.SampleQty).Result,
                                          btnvisible= BtnVisibility((int)(k.Capacity - k.SampleQty), k.SampleQty).Result,
                                      }).ToList();


Answers (7)