我如何在MVC中使用linq编写(在select中选择) [英] How I write (select where in select ) using linq in MVC
本文介绍了我如何在MVC中使用linq编写(在select中选择)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在sql中写这个查询: -
i write this query in sql :-
select * from ClientsNotifications
where LocationCenterID in (
select UserLocationsCenter.LocationCenterID
from UserLocationsCenter
inner join AspNetUsers on UserLocationsCenter.UserID = AspNetUsers.Id
where AspNetUsers.Email = 'mahmoud.omar@yahoo.com')
order by UploadDate desc
我想用linq写它,我是怎么做的;
我尝试了什么:
i尝试在mvc中使用linq编写此查询,但我不能
and i want write it using linq , how i do that;
What I have tried:
i try write this query using linq in mvc but i can't
推荐答案
试试这个
try this
var LocationCenterIDs = (from ulc in lstUserLocationsCenter join asp in lstAspNetUsers on ulc.UserID equals asp.Id select ulc.LocationCenterID);
var result = lstClientsNotifications.Where(k => LocationCenterIDs.Contains(k.LocationCenterID)).OrderByDescending(k => k.UploadDate).ToList();
替换List用你的对象名称
replace the List with your object names
这篇关于我如何在MVC中使用linq编写(在select中选择)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文