using System.Collections.Generic;
public static void Main()
new { Guid = 1, Question = "question 1", UserId = 1 },
new { Guid = 2, Question = "question 2", UserId = 2 },
new { Guid = 3, Question = "question 3", UserId = 1 },
new { VoteId = 1, UserId = 1, PollGuid = 1, Value = 1010.1 },
new { VoteId = 2, UserId = 2, PollGuid = 1, Value = 2010.1 },
new { VoteId = 3, UserId = 3, PollGuid = 1, Value = 3010.1},
new { VoteId = 4, UserId = 1, PollGuid = 2, Value = 4010.1 },
TblPolls = TblPolls.AsQueryable(),
TblVotes = TblVotes.AsQueryable(),
foreach (var userId in new [] { 1, 2, 3, 30303030 })
foreach (var guid in new [] { 1, 2, 3, 101010 })
from poll in ctx.TblPolls
join vote in ctx.TblVotes.Where(v => v.UserId == userId && v.PollGuid == guid) on poll.Guid equals vote.PollGuid into gg
from vote in gg.DefaultIfEmpty()
value = (vote != null ? vote.Value : -1),
Console.WriteLine($"\nFor {new { guid, userId }}:");
selectedPolls.Select(p => p.ToString()).ToArray().Dump();
public int Guid { get; set; }
public string Question { get; set; }
public int UserId { get; set; }
public int VoteId { get; set; }
public int UserId { get; set; }
public int PollGuid { get; set; }
public static class Extensions
public static TOut As<TOut>(this TOut o) => o;