【发布时间】:2020-06-01 13:19:20
【问题描述】:
我已经写了 Linq Query,我想把它做成 Lambda 表达式。如何编写 Lambda 表达式 代替 return 语句 Linq 查询。实体表是entities.Users,entities.Users,entities.ponds
查询表达式:
from pond in Ponds
join customerdevice in CustomerDevices on pond.Imei equals customerdevice.Imei
join user in Users on customerdevice.CustomerId equals user.CustomerId
where user.Username=="user1"
select new { temp = pond.Temp, imei = pond.Imei,timestamp=pond.Timestatmp }
Lambda 表达式:
public async Task<IHttpActionResult> GetAllData(int deviceid)
{
using (smartpondEntities entities = new smartpondEntities())
{
try
{
return Ok(await entities.ponds.Where(u=>u.deviceid==deviceid).OrderByDescending(u => u.timestatmp).ToListAsync());
}
catch (Exception Ex)
{
return BadRequest("Sorry Error Found!!!");
}
}
}
【问题讨论】:
-
我已经修改了我的问题,你可以检查一下