Home > Mobile >  How to perform in and not in operation just like in SQL without using SQL query or SQL / table
How to perform in and not in operation just like in SQL without using SQL query or SQL / table

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 C# 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