I have the following domain model setup using EF code first:
public class User
{
public virtual int Id { get; set; }
public virtual string Email { get; set; }
public virtual ICollection<UserProcessed> UsersProcessed { get; set; }
}
public class UserProcessed
{
public virtual int Id { get; set; }
public virtual DateTime CreatedAt { get; set; }
public virtual User user { get; set; }
}
I am trying to translate the following T-SQL query into LINQ and I am having some difficulties:
SELECT u.Email
FROM Users u LEFT JOIN UsersProcessed up ON u.Id = up.UserId
WHERE up.UserId IS NULL
AND u.CreatedAt BETWEEN '2011-12-01' AND '2011-12-01'
This will return all users that have not been processed (UserId does not exist in UsersProcessed table).
IEnumerable<User> users = Database.Set<User>().Where(....).ToList();
This may not translate to exactly the same query when SQL is produced, but it should do the trick: