I'm working with EF code first. There are two classes which define my many to many association tables:
public class UserProfile
{
[Key]
[DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
public int UserId { get; set; }
public string Email { get; set; }
public virtual ICollection<Habit> Habits { get; set; }
}
public class Habit
{
[Key]
public int HabitId { get; set; }
public virtual ICollection<UserProfile> Users { get; set; }
}
I need to select from my database all habits for current user. I'm very new to c#, and the problem is that I can't understand how to work with complex lambda-expressions. I tried that:
context.Habits.Where(habit => habit.Users
.Where(user=>user.Email==User.Identity.Name)).ToList()
But it's wrong. Could you please correct my lambda-based query. Thanks.