您好,我需要帮助将SQL查询转换为linq EF [英] Hello gues I need help with convert an SQL query to linq EF
本文介绍了您好,我需要帮助将SQL查询转换为linq EF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是查询
当我在Linq写的时候出现错误
选择u.user_name,max( l.last_action_date)
来自用户你加入system_log l on u.user_id = l.user_id
group by u.user_name
我尝试了什么:
错误在某些情况下是
指定的LINQ表达式包含对与不同上下文关联的查询的引用。
this is the query
when i wrote it in Linq an error appear
select u.user_name ,max(l.last_action_date)
from Users u join system_log l on u.user_id = l.user_id
group by u.user_name
What I have tried:
the error in some case is
The specified LINQ expression contains references to queries that are associated with different contexts.
推荐答案
以下是如何执行max:
c# - 使用Linq to SQL,如何在表中找到列的最小值和最大值? - 堆栈溢出 [ ^ ]
以下是分组方式:
Here's how you do max:
c# - Using Linq to SQL, how do I find min and max of a column in a table? - Stack Overflow[^]
Here is how you group by:
var totalProdcuts = from o in ctx.Orders
join p in ctx.Products on o.ProductId equals p.Id
group o.NumberOf by p.Name into g
select new { ProductName = g.Key, TotalOrdered = g.Sum() };
这篇关于您好,我需要帮助将SQL查询转换为linq EF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文