Click here to Skip to main content
15,905,590 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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


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
Posted
Updated 11-Feb-17 21:07pm

1 solution

try this

C#
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();

replace the List with your object names
 
Share this answer
 
Comments
MahmoudOmar 12-Feb-17 3:49am    
i write :-
var email = (string)Session["email"];

and i edit in LocationCenterIDs :-

var LocationCenterIDs = (from ulc in db.UserLocationsCenter join asp in db.AspNetUsers on ulc.UserID equals asp.Id where asp.Email == email select ulc.LocationCenterID);

var result = db.ClientsNotifications.Where(k => LocationCenterIDs.Contains(k.LocationCenterID)).OrderByDescending(k => k.UploadDate).ToList();

return View(result);

and give me this Error :-
An error occurred while executing the command definition. See the inner exception for details.
MahmoudOmar 12-Feb-17 4:22am    
i solve my problem and this code work thanks for help
Karthik_Mahalingam 12-Feb-17 4:23am    
Cool

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900