[英]Get max date with linq where condition, inside query
I have the following two tables that store the calls that the users made, 我有以下两个表存储用户拨打的电话,
Users
-----
IdUser int PK,
Name varchar(50)
Calls
------
idCall int PK,
idUser int FK,
CallDate datetime
This is the code i tried but i cant seem to get it to work 这是我尝试过的代码,但我似乎无法使它正常工作
var resultado = (from Users in ctx.Users
join Calls in cts.Calls on Users.idUser equals Calls.idUser
select new
{
Name= Users.Name,
MaxDate=(from c in Calls select c.CallDate).Where(u=>u.IdUser==Users.IdUser).Max()
}).ToList();
Example: I have 例子:我有
User:
-----
0 John Doe
Calls:
------
0 0 23/11/2015
0 0 25/11/2015
0 0 26/11/2015
The query should return 查询应返回
Alan 26/11/2015
Not tested, but does something like this work? 未经测试,但是这样的工作吗?
var resultado = (from Users in ctx.Users
select new
{
Name= Users.Name,
MaxDate=(from c in ctx.Calls where c.IdUser == Users.IdUser select c.CallDate).Max()
}).ToList();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.