Home > front end >  How to perform in and not in operation in ASP.NET Core MVC just like in SQL without using SQL query
How to perform in and not in operation in ASP.NET Core MVC just like in SQL without using SQL query

Time:07-10

This is the SQL query

select * 
from Students
where StudentID in (select StudentID from FeeEntry);

I want to perform this SQL query in ASP.NET Core MVC without using SQL query command or any other procedure or with SqlDataAdapter.

I want this format.

The format of ASP.NET Core MVC code:

var myvalues = (from values in  _context.students
                where values.studentID in table2   // where studentID is the foreign key 
                select values).ToList();

CodePudding user response:

You can use entity framework, you can find information here:

  1. Read about entity framework here.
  2. Read about LINQ to SQL here.

Then your code would look like this:

    var ids = _context.FeeEntry.Select(x => x.StudentID).tolist();
    var myvalues =  _context.students.where(x => ids.Contains(x.studentID)).toList();
  • Related