I have two tables that I want to join using predicate builder. In pseudo code, I want to return all StudentSchedule rows, joining with Student on StudentId, where StudentLastName = "Smith".
public class Student
{
int StudentId {get;set;}
string StudentFirstName {get;set;}
string StudentLastName {get;set;}
}
class StudentSchedule
{
int StudentScheduleId
int StudentId
string ClassName
}
I can do it for one entity just fine-
var studentBuilder = PredicateBuilder.True<Student>();
studentBuilder = studentBuilder.And(Student => Student.StudentId == studentId);
var students = context.Students.Where(studentBuilder).ToList();
Then you should change your model to something like this:
Then your query would be:
Without predicate builder:
My personal preference is to not repeat the entity type in the properties unless it's an external property, so my model would be like this:
Of course you might want a more detailed model that has "Subjects" (Name, Prerequisites, etc), "Classes" (A subject, a classroom, schedules, Staffs), "Students" (FirstName, LastName, Classes), "Staff" (FirstName, LastName, JobTitle, Classes) and "Schedules" (Day of week, start time, end time, Classes).