SQL 转换 LINQ 求助
小弟对LINQ不熟悉,请各位帮忙转换个SQL,谢谢:
select CourseId, SUM(DATEDIFF(MI, cvr.StartTime, cvr.EndTime)) AS Sumtimes
from CourseViewRecords cvr
inner join Users u on cvr.UserId = u.UserID AND u.IsAssist = 1
group by CourseId
order by Sumtimes desc
另外,听说LINQPAD可以转换SQL为LINQ,但不知道如何操作,有熟悉的各位大大,麻烦也告知下,谢谢。。
------解决方案--------------------db.CourseViewRecords.Join(db.Users.Where(y => y.IsAssist == 1), x => x.UserId, x => x.UserID, (cvr, u) => new { cvr, u }).GroupBy(x => x.cvr.CourseId).Select(x => new { CourseId = x.Key, Sumtimes = x.Sum(y => y.cvr.EndTime.Month - y.cvr.StartTime.Month)});
------解决方案-------------------- var ary = (from cvr in CourseViewRecords from u in Users where cvr.UserId == u.UserID && u.IsAssist == 1 group cvr by cvr.CourseId into g select new { id = g.Key, sumtimes = g.Sum(t => (t.EndTime - t.StartTime).Milliseconds) }).OrderByDescending(t => t.sumtimes);
------解决方案--------------------http://code.msdn.microsoft.com/101-LINQ-Samples-3fb9811b
------解决方案--------------------LINQPAD应该只有LINQ转换成SQL吧。
默认结果视图
由语句返回的对象和文本的简单图形
Lambda视图
LINQ表达式转换为可用的Lambda表达式
SQL视图
LINQ表达式转换为可用的SQL
IL视图
针对代码生成的微软中间语言