Guy's我需要此sql語句的Lambda表達式。將sql轉換爲Lambda表達式
select GalleryId, Max(Bid)
from BidModels
where GalleryId in (select GalleryId from BidModels where UserId = (UserId))
group by GalleryId
Guy's我需要此sql語句的Lambda表達式。將sql轉換爲Lambda表達式
select GalleryId, Max(Bid)
from BidModels
where GalleryId in (select GalleryId from BidModels where UserId = (UserId))
group by GalleryId
這裏是你如何能做到這
var galleryIds = (bidModelses.Where(b => b.UserId == [YOURPARAMETER])
.Select(b => b.GalleryId));
var query = (bidModelses.Where(bm => galleryIds.Contains(bm.GalleryId))
.GroupBy(bm => bm.GalleryId)
.Select(gbm => new {gbm.Key, MaxBid = gbm.Max(p => p.BidId)}));
我不明白爲什麼你需要的子查詢,因爲你可以選擇其中傳遞用戶ID =用戶ID的所有投標;與記:
var userid = <whatever>;
var query = from b in BidModels
where b.UserId = userid
group by b.GalleryId into g
select new {Id = g.Key, MaxBid = g.Max(x => x.Bid)};
我正在嘗試查詢數據庫,以查找特定於與所有用戶的出價相關的用戶的出價出價。換句話說,我希望一個投標人知道他的出價與他的同一套產品的其他出價有關。 –
這似乎是答案感謝您的幫助:
from b in BidModels
let MyGallery = from a in BidModels where a.UserId == (1) select new { a.GalleryId }
where MyGallery.Any()
group b.Bid by b.GalleryId into g
select new
{ Id = g.Key,
MaxBid = g.Max()
}
userid = userid是一個no-op(總是爲true)。你是否打算將其中的一個作爲輸入參數? – Hogan
對不起,用戶ID是變量應該是用戶ID =一些PARR? –
你確定你的意思是lambda或是LINQToSQL? – Nilesh