簡體   English   中英

將IGrouping轉換為IQueryable

[英]Convert IGrouping to IQueryable

我有一個名為CelebrityLocation的模型,除了其他屬性之外,還有一個名人模特。

所以;

public partial class CelebrityLocation
  public Celebrity Celebrity {get; set;}

我想獲得所有CelebrityLocation對象的列表,但是Celebrity中的CelebrityLocation分組。

我得到IGroupng的返回類型,但我需要將其轉換為IQueryable<CelebrityLocation>

以下是我到目前為止所嘗試的內容。

IQueryable<CelebrityLocation> returnSet = (IQueryable<CelebrityLocation>) dc.CelebrityLocations.OrderByDescending(x => x.DateTime).GroupBy(x => x.Celebrity);

編輯

在這種情況下,AutoMapper是否可行?

你想只是讓那些分組的元素彼此相鄰嗎? IQueryable<CelebrityLocation>

如果是這樣,這應該有所幫助:

IQueryable<CelebrityLocation> returnSet = dc.CelebrityLocations.OrderByDescending(x => x.DateTime).GroupBy(x => x.Celebrity).SelectMany(x => x);

將您的查詢更改為:

dc.CelebrityLocations.OrderByDescending(x => x.DateTime).AsQueryable().GroupBy(x => x.Celebrity).Select(x => x.First());

你可以調用AsQueryable()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM