I have two objects: Poll and PollIp (one-to-many).
I want to select all polls that not have concrete Ip address. How can I do this?
My code:
public Poll GetNextPoll(string ipAddress)
{
return Database.Polls
.Where(p => p.IsPublish.Value && p.PollIps.Any(i => i.IpAdress != ipAddress))
.FirstOrDefault();
}
Thanks
EDIT
In the DB I have following:
Poll:
id Name ...
1 Poll1
2 Poll2
PollIp
PollId IpAdress
1 ::1 (it's my IP)
And, query must return Poll with id equal 2, because in the PollIp no PollId with 2
1 Answer