Asp.net mvc linq中的排序和加入 AllMovieInfo=来自AllMovieInfo中的movieInfo 来自movieInfo.SeenItWantToSeenIt中的countryMovie 其中countryMovie.Status==1 选择电影信息; var seenitorderby=db.SeenItWantToSeeIt.Where(m=>m.Status==1).GroupBy(m=>m.MovieID).Select(g=>new{MovieID=g.Key,count=g.count()}).OrderBy(o=>o.count); List seenItList=seenitorderby.Select(s=>s.MovieID.ToList(); AllMovieInfo=(来自AllMovieInfo中的a) 来自seenItList中的s 其中seenItList.Contains(a.MovieID) 选择a).Distinct();

Asp.net mvc linq中的排序和加入 AllMovieInfo=来自AllMovieInfo中的movieInfo 来自movieInfo.SeenItWantToSeenIt中的countryMovie 其中countryMovie.Status==1 选择电影信息; var seenitorderby=db.SeenItWantToSeeIt.Where(m=>m.Status==1).GroupBy(m=>m.MovieID).Select(g=>new{MovieID=g.Key,count=g.count()}).OrderBy(o=>o.count); List seenItList=seenitorderby.Select(s=>s.MovieID.ToList(); AllMovieInfo=(来自AllMovieInfo中的a) 来自seenItList中的s 其中seenItList.Contains(a.MovieID) 选择a).Distinct();,asp.net-mvc,linq-to-entities,Asp.net Mvc,Linq To Entities,seenitorderby提供了看过最多的电影的所有id。所以我想加入AllMovieInfo,它是从其他参数筛选movieinformation。 这个查询是根据“AllMovieInfo.MovieID”对结果进行排序的,这很明显,但我必须根据“seenitorderby”的id对“结果”进行排序,例如:seenitorderby可能会使用MovieID 2,25,7,14,25,然后我需要按照seenitorderby相同的顺序对所有MovieInfo进行排序。如何根据“seenitord

seenitorderby提供了看过最多的电影的所有id。所以我想加入AllMovieInfo,它是从其他参数筛选movieinformation。
这个查询是根据“AllMovieInfo.MovieID”对结果进行排序的,这很明显,但我必须根据“seenitorderby”的id对“结果”进行排序,例如:seenitorderby可能会使用MovieID 2,25,7,14,25,然后我需要按照seenitorderby相同的顺序对所有MovieInfo进行排序。如何根据“seenitorderby”对“结果”进行排序?

您不能将seenitlist用作主要列表并加入到movieinfo吗?我相信(尽管我还没有尝试过)它们会按照主要列表的顺序出现

 AllMovieInfo = from movieInfo in AllMovieInfo
                           from countryMovie in movieInfo.SeenItWantToSeenIt
                           where countryMovie.Status==1
                           select movieInfo;

            var seenitorderby = db.SeenItWantToSeeIt.Where(m => m.Status == 1).GroupBy(m => m.MovieID).Select(g => new  {MovieID =g.Key,count=g.Count()}).OrderBy(o=>o.count);
            List<int> seenItList=seenitorderby.Select(s=>s.MovieID).ToList();
            AllMovieInfo = (from a in AllMovieInfo
                       from s in seenItList
                       where seenItList.Contains(a.MovieID)
                       select a).Distinct();

如果您真的愿意,您可能会将所有linq查询简化为一个,这可能会使下一位来阅读代码的人更容易理解

AllMovieInfo在IQueryable中,join不能强制转换为IEnumerables一个简单的解决方案,请尝试AllMovieInfo.AsEnumerable()(从SeeUnitList中的s在s上的AllMovieInfo中加入a等于a.MovieID选择a)。Distinct().AsQueryable();
from s in seenItList
join a in AllMovieInfo on s equals a.MovieId
select a