I'am trying to write the following query in linq syntax but i can make it. I'am getting errors at the marked line Error The best overloaded method match for 'System.Collections.Generic.List<AnonymousType#1>.Contains(AnonymousType#1)' has some invalid arguments
. How can i write it properly ?
sql:
select * from [dbo].[TableOrder]
where TableID not in (
select tbl.TableID from [dbo].[TableOrder] tbl
left join [dbo].[Restorant] r on tbl.RestorantID = r.RestorantID
left join [dbo].[Reservation] res on res.TableID = tbl.TableID
where ReservationDate = '15.06.2014' and ResStartTime = '2100' and ResEndTime='2299')
linq:
var query = (from t in db.TableOrderTbls.AsQueryable()
join r in db.RestorantTbls on t.RestorantID equals r.RestorantID
join res in db.ReservationTbls on t.TableID equals res.TableID
where (resv.RseservationDate == res.ReservationDate && resv.RestorantName == r.RestorantName) && ((Convert.ToInt32(resv.ResStartTime) < Convert.ToInt32(res.ResStartTime) &&Convert.ToInt32(resv.ResEndTime) < Convert.ToInt32(res.ResStartTime))||((Convert.ToInt32(resv.ResStartTime) > Convert.ToInt32(res.ResEndTime) && Convert.ToInt32(resv.ResEndTime) > Convert.ToInt32(res.ResEndTime))))
select new {r.RestorantName, r.RestorantID, t.TableID, t.TableType}).ToList();
var q = from t in db.TableOrderTbls.AsQueryable()
where query.Contains(t.TableID) // ERROR LINE
select t;
selectis returning a new anonymous type, containing 4 properties. You are treating it as if it contains just 1 in your call toquery.Contains(t.TableID). Using your code as-is, you would need to pass your anonymous type to theContainsmethod.