Reputation: 29
Here's an example of the query I'm trying to convert to entity framework
select * from Teachers fm
where (select count(*) from General_Program
where Teacher_id = fm.Teacher_ID and Campus_Name = fm.Campus_Name) > 0
and Dept_Name = 'English'
Upvotes: 0
Views: 143
Reputation: 26
// Without relation between Teachers and General_Program:
var teachers = _context.Teachers.Where(t => t.Dept_Name = "English" && _context.General_Program.Any(p => p.Campus_Name = t.Campus_Name && p.Teacher_id = t.Teacher_ID));
// When Teachers are related to General_Program (only on ID):
var teachers = _context.Teachers.Where(t => t.Dept_Name = "English" && t.General_Program.Any(p => p.Campus_Name = t.Campus_Name));
// In case of Teachers are related to General_Program (key contains both ID and campus):
var teachers = _context.Teachers.Where(t => t.Dept_Name = "English" && t.General_Program.Any());
Upvotes: 1