0

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'
0

1 Answer 1

1
// 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());
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.