このクエリを変換してカスタムDTO型オブジェクトに出力しようとしています。私はGroupByとOrderByを使用してカスタムオブジェクトにLINQ-to-SQLクエリを投影する方法
return from page in db.Pages
where intItemIdArray.Contains(page.pageId)
group page by page.pageId into g
orderby g.Max(x => x.pageId)
select g.OrderByDescending(t => t.revision).First();
。私が渡し
int[]
ための最高のリビジョン番号を持つページだけを取得したいが、私はそれは
select (new JPage {pageid = g.pageId, title = g.title, etc})
.OrderByDescending(t => t.revision)
.First();
ようなもので
select g.OrderByDescending(t => t.revision).First();
を交換しようとすると、誰も助けてくれますか?
これは私が好きではないが、それは完全に働いている、と私は現在、これを超えて最適化する必要はありません。これは、私が現在行っているものです。
誰かがこれを改善することができたらうれしいです。
var pages = from page in db.Pages
where intItemIdArray.Contains(page.pageId)
group page by page.pageId into g
orderby g.Max(x => x.pageId)
select g.OrderByDescending(t => t.revision).First();
return pages.Select(x => new JPage() {
pageId = x.pageId,
pageKey = x.pageKey,
title = x.title,
body = x.body,
isFolder = x.isFolder.ToString(),
leftNode = x.leftNode,
rightNode = x.rightNode,
revision = x.revision,
sort = x.sort,
createdBy = x.createdBy.ToString(),
createdDate = Utility.DateTimeToUnixTimeStamp(x.createdDate).ToString(),
modifiedDate = Utility.DateTimeToUnixTimeStamp(x.modifiedDate).ToString(),
pageVariationId = x.pagesVariationId,
parentId = x.parentId
})
.AsQueryable();
右の括弧が欠けています。 'etc})。 –
ねえ、ありがとう、ありがとう、もし私がそれを見逃していたら、私はそれを捕まえるだろう。これらのlinqクエリについてちょっとばかげているだけです! –