Default if empty with LINQ to entities
Posted
by J. Pablo Fernández
on Stack Overflow
See other posts from Stack Overflow
or by J. Pablo Fernández
Published on 2009-07-14T18:11:31Z
Indexed on
2010/03/21
10:31 UTC
Read the original article
Hit count: 297
In a LINQ to entities expression like this:
var vote = (from vote in db.Vote where
vote.Voter.Id == user.Id
select v).FirstOrDefault();
how do you you add a DefaultIfEmpty so that when there's no vote I'd get a default value?
© Stack Overflow or respective owner