Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linq 在实体框架中的运算符中实现_Linq_Entity Framework_Extension Methods - Fatal编程技术网

Linq 在实体框架中的运算符中实现

Linq 在实体框架中的运算符中实现,linq,entity-framework,extension-methods,Linq,Entity Framework,Extension Methods,我尝试在实体框架中实现这个SQL查询 select * from students where student.fieldid in (select fieldid from fields where groupid = 10) 我想这是一种方法: var fields = context.fields.where(t=>t.groupid = 10).toList(); var result = context.students.where(t=> fields.Conta

我尝试在实体框架中实现这个SQL查询

select * 
from students 
where student.fieldid in (select fieldid from fields where groupid = 10)
我想这是一种方法:

var fields = context.fields.where(t=>t.groupid = 10).toList();

var result = context.students.where(t=> fields.Contains(t.fieldid)).toList();
但这是行不通的


还有其他人尝试过这样做吗?

中的SQL
相当于LINQ
包含的

var names = new string[] { "Alex", "Colin", "Danny", "Diego" };    
var matches = from person in people
              where names.Contains(person.Firstname)
              select person;
因此,SQL语句:

select * from students where student.fieldid in ( select fieldid from fields 
where groupid = 10)
在LINQ中等同于:

var fieldIDs= from  Fids in db.fields
              where Fids.groupid==10
              select Fids.fieldid;

var results= from s in db.students
             where fieldIDs.Contains(s.fieldid)
             select s;