我有以下两个表来存储用户进行的调用,
Users
-----
IdUser int PK,
Name varchar(50)
Calls
------
idCall int PK,
idUser int FK,
CallDate datetime
这是我试过的代码,但我似乎无法让它工作
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();
示例:我有
User:
-----
0 John Doe
Calls:
------
0 0 23/11/2015
0 0 25/11/2015
0 0 26/11/2015
查询应该返回
Alan 26/11/2015
答案 0 :(得分:1)
没有经过测试,但做过类似的工作吗?
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();