Home > Back-end >  LINQ Query To Return List Where Condition Is Based On Another Table
LINQ Query To Return List Where Condition Is Based On Another Table

Time:01-08

So I Have Two Tables Cars And Booking ,

And I Want Following SQL Query's Equivalent LINQ Version and I'm struggling with it

THE SQL QUERY IS:

SELECT * FROM CARS WHERE Car_id NOT IN (SELECT Car_Id From Bookings WHERE JourneyCompletion='OnGoing');

And The Result Should Be List Of Cars , How To Achiveve This Using Linq?

CodePudding user response:

Try Below Code:

var Q1 = (from row in DbContext.Bookings where row.JourneyCompletion=='OnGoing' select row).ToList();
var Q2 = (from row in DbContext.CARS.where(n=> !n.Car_Id.Contains(n.Car_id))).ToList();
  •  Tags:  
  • Related