Select or SelectList: I Want to include the entire entity

僤鯓⒐⒋嵵緔 提交于 2019-12-04 15:21:15

another way to query it

var allMediaFiles = session.QueryOver<MediaFile>().Where(...).ToFuture(); // just get the MediaFiles into sessionCache

var results = session.QueryOver<PlaylistEntry>()
    .Where(p => p.MediaFile...)
    .SelectList(list => list
        .GroupBy(p => p.MediaFile.Id)
        .CountDistinct(p => p.Playlist))
    .ToFuture<object[]>()
    .Select(a => new MediaFileAndCount
    {
        MediaFile = session.Get<MediaFile>((long)a[0]),
        DistinctPlaylistCount = (int)a[1]
    })
    .ToList();

foreach (var mediaFile in allMediaFiles.Except(results.Select(r => r.MediaFile)))
{
    results.Add(new MediaFileAndCount { MediaFile = mediaFile });
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!