我需要获得Students
所有Registration
的{{1}} {/ 1}}。
我原以为它会是Realisation
,但它不起作用:)。我试图在示例代码中做到这一点,但我得到:s => s.Registrations.RealisationId == realisationId
。我不知道如何才能正确地写出这个表达式,有人可以帮我解决这个问题吗?
我无法弄清楚如何更好地标题这个问题,抱歉。
A lambda expression with a statement body cannot be converted to an expression tree
public class Student : BaseEntity {
public int StudentId {get; set;}
public virtual ICollection<Registration> Registrations {get; set;}
}
public class Registration : BaseEntity {
public int RegistrationId {get; set;}
public int StudentId {get; set;}
public int RealisationId {get; set;}
public Student Student {get; set;}
public Realisation Realisation {get; set;}
}
public class Realisation : BaseEntity {
public int RealisationId {get; set;}
public virtual ICollection<Registration> Registrations {get; set;}
}
答案 0 :(得分:3)
您需要选择ID并使用Contains
:
return Context.Set<Student>()
.Where(s => s.Registrations
.Select(r => r.RealisationId)
.Contains(realisationId));
通常这会转换为WHERE IN
子句。