Reputation: 9
Flag value true only if the row exist otherwise make it false.
I solved the solution in SQL but I'm having a problem with entity framework. Here is the SQL query:
select p.ProductID,
(case when c.UserID = 3 then 'true' else 'false' end) as flag
from product as p
left join SavedItem as c
on p.ProductID = c.ProductID
This query runs accurately, it shows all records and only makes flag true if the column exists in a SavedItem
table.
How can I do that in entity framework?
Upvotes: 0
Views: 313
Reputation: 978
this might be a problem of left join in Entity framework. Try this code:
var result = from p in Product
join c in SavedItem on p.ProductID equals c.ProductID into lj
from c in lj.DefaultIfEmpty()
select new {
p.ProductID,
flag = (c.UserID == 3 ? 'true' : 'false')
};
Upvotes: 1