LINQ, Unable to create a constant value of type XXX. Only primitive types or enumeration types are supported in this context

前端 未结 5 638
我寻月下人不归
我寻月下人不归 2020-11-30 01:58

In my application I have Lecturers and they have list of Courses they can teach and when I\'m deleting a course I want to remove connection to lecturers. Here\'s the code:

5条回答
  •  天涯浪人
    2020-11-30 02:41

    You cannot compare complex type, if you have not specified what you mean for equality.

    As exception detail says, you need to check primitive values (like Integer in your case).

    And better to use Any() method instead.

    var toRemove = db.Lecturers
         .Where(l => l.Courses.Any(p=>p.Id == courseFromDb.Id)).ToList();
    

提交回复
热议问题