读书人

求一SQL语句在EF中写法,该怎么处理

发布时间: 2012-09-14 23:00:49 作者: rapoo

求一SQL语句,在EF中写法
select n.* ,b.FileName from NewsInfo n left join

(select fid,filename from brandfile where typeid=2 and fileid in (select max(fileid) from brandfile group by fid) ) b

on n.newsid=b.fid

[解决办法]

C# code
var maxids = brandfile.GroupBy(x => x.fid).Select(g => g.Max(x => x.fieldid));var b = brandfile.Where(x => x.typeid == 2 && maxids.Contains(x => x.fileid));var result = from n in NewsInfo              join b in brandfile on n.newsid equals b.fid into n1             from n2 in n1.DefaultIfEmpty()             select new              {                NewsInfo = n,                FileName = b.filename             };
[解决办法]
探讨
select n.* ,b.FileName from NewsInfo n left join

(select fid,filename from brandfile where typeid=2 and fileid in (select max(fileid) from brandfile group by fid) ) b

on n.newsid=b.fid

读书人网 >.NET

热点推荐