如何在不使用SQL查询或SQL /表的情况下像在SQL中一样执行in和not in操作



这是SQL查询

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

我想在ASP中执行这个SQL查询。. NET Core MVC,不使用SQL查询命令或任何其他过程,也不使用SqlDataAdapter.

我想要这个格式。

c#代码格式:

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

你可以使用实体框架,你可以在这里找到信息:

  1. 在这里阅读实体框架。
  2. 在这里阅读LINQ to SQL。

那么你的代码看起来像这样:

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

最新更新