[英]Adding where clause in linq
I am new to Linq. 我是Linq的新手。 Please help.On this query i need to add where clause (like EMPLOYEE_ID==10
).db stands dbcontext. 请帮助。在此查询上,我需要添加where子句(例如EMPLOYEE_ID==10
)。db代表dbcontext。
var query = db.EmpQualifications.Select(EmpQu => new {
EMP_QUALI_ID = EmpQu.EMP_QUALI_ID,EMPLOYEE_ID = EmpQu.EMPLOYEE_ID,
}).OrderBy(D => D.EMP_QUALI_ID);
Simply Add the where
clause before Select
只需在Select
之前添加where
子句
var results = db.EmpQualifications
.Where(r=> r.EMPLOYEE_ID == 10)
.Select(EmpQu =>
new {
EMP_QUALI_ID = EmpQu.EMP_QUALI_ID,
EMPLOYEE_ID = EmpQu.EMPLOYEE_ID,
})
.OrderBy(D => D.EMP_QUALI_ID);
You can use it like; 您可以像这样使用它;
var query = db.EmpQualification
.Where(e => e.MPLOYEE_ID==10)
.Select...
You can read more information fromm where clause - Query Keywords
您可以从where clause - Query Keywords
读取更多信息where clause - Query Keywords
The where clause is a filtering mechanism. where子句是一种过滤机制。 It can be positioned almost anywhere in a query expression, except it cannot be the first or last clause . 它可以位于查询表达式中的几乎任何位置, 但不能为first或last子句 。 A where clause may appear either before or after a group clause depending on whether you have to filter the source elements before or after they are grouped. where子句可能出现在group子句之前或之后,具体取决于您是否必须在对源元素进行分组之前或之后对其进行过滤。
在Select
之前添加Where
扩展方法
var query = db.EmpQualifications.Where(x => x.MPLOYEE_ID==10).Select....
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.