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
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();
Amit MohantyPosted Sep 11, 2023, 6:21 AM
Prasad RaveendranPosted Sep 10, 2023, 4:26 PM
I have provided the updated query
In this corrected query:
We first perform the join and ordering as before.
We use
.AsEnumerable()to switch to LINQ to Objects, allowing us to use theEnumerable.Selectmethod for generatingRowNumberandRankVendor.In the final
Selectmethod, we use theindexparameter to calculateRowNumber. We also computeRankVendorby resetting it to 0 whenever a newRackvalue is encountered.This should correctly calculate the
RowNumberbased onm.IdandRankVendorbased onm.Rack.Prasad RaveendranPosted Sep 10, 2023, 4:22 PM
We first perform the join and ordering as before.
We use
.AsEnumerable()to switch to LINQ to Objects, allowing us to use theEnumerable.Selectmethod for generatingRowNumberandRankVendor.In the final
Selectmethod, we use theindexparameter to calculateRowNumber. We also computeRankVendorbased on theRackcolumn, appending the row number ifRackis not null, or just using the row number itself ifRackis null.This may help you
Edwin KlesmanPosted Sep 7, 2023, 12:52 PM
PS: I generated this with my (sideproject gone product) linqmeup.com
Mariraj KPosted Jul 24, 2023, 7:19 AM
using (var context = new YourDbContext()) { var query = from m in context.MstStorage join s in context.tblStorageBatch on m.Id equals s.StorageId into storageBatchJoin from s in storageBatchJoin.DefaultIfEmpty() select new { RowNumber = (from m2 in context.MstStorage where m2.Id <= m.Id select m2).Count(), Rankvendor = (from m2 in context.MstStorage where m2.Rack == m.Rack && m2.Id <= m.Id select m2).Count(), m.Id, m.Rack, m.Capacity, s.BatchId, s.SampleQty }; // Execute the query var result = query.ToList(); }
Sandeep KumarPosted Jul 15, 2023, 5:28 AM
Your Query Result not matched against my sql query,
pls look into it
Nabeel HassanPosted Jul 14, 2023, 1:31 PM