我正在使用EF代碼。這裏是定義我的多對多關聯表兩類:實體框架如何與ASP.NET MVC中的lambda表達式一起工作
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; }
}
我需要從我的數據庫選擇當前用戶的所有習慣。我對c#很陌生,問題是我無法理解如何使用複雜的lambda表達式。我試過了:
context.Habits.Where(habit => habit.Users
.Where(user=>user.Email==User.Identity.Name)).ToList()
但是這是錯誤的。您能否糾正我的基於lambda的查詢。謝謝。
user.Email == User.Identity 。名稱 ? – octref