使用 LINQ To Select 基于子集合项的记录

Using LINQ To Select Records Based on Child Collections item

我有导师class。

public partial class Instructor
{
    public Instructor()
    {
        this.Courses = new HashSet<Course>();
        this.Courses1 = new HashSet<Course>();
    }

    public int ID { get; set; }
    public string FName { get; set; }
    public string LName { get; set; }
    public int UserID { get; set; }

    public virtual ICollection<Course> Courses { get; set; }
    public virtual User User { get; set; }
    public virtual ICollection<Course> Courses1 { get; set; }
}

我想按姓名和教授的课程搜索讲师 我用谓词来建立我的条件 但我需要访问讲师内部的课程 1 集合,以找到教授这门课程的讲师,但我不能

var Predict = PredicateBuilder.True<Instructor>();

        if (chkNameSearch.Checked)
        {
            Predict = Predict.And(ins => ins.FName == txtNameSearch.Text);
        }

        if (chkCourseSearch.Checked)
        {

            int CourseID=int.Parse(cmbCourseSearch.SelectedValue.ToString());
            Predict = Predict.And(ins => ins.Courses1.ID == CourseID);  //Error
        }

课程 1 没有任何 ID 属性。尝试这样做:

Predict = Predict.And(ins => ins.Courses1.Any(c => c.ID == CourseID));