将 SQL 转换为 LINQ 格式的 where 子句
Posted
技术标签:
【中文标题】将 SQL 转换为 LINQ 格式的 where 子句【英文标题】:Converting SQL to LINQ formatting where clause 【发布时间】:2012-09-06 10:03:23 【问题描述】: Qry = "select childID,ChildEmail,ChildUserID, ChildPassword from ChildProfile ";
Qry = Qry + " where ucase(ChildFName) = '"
+ Strings.UCase(Strings.Trim(Txtname.Text))
+ "' and ucase(childlname) = '"
+ Strings.UCase(Strings.Trim(txtSurName.Text))
+ "' and childmobile = '"
+ Strings.Trim(txtMobile.Text) + "'";
我们如何将此查询转换为 LINQ
List<PatientDTO> lstChildProf = objService.GetAllPatient();
lstChildProf = new List<PatientDTO>(
from l in lstChildProf where
);
这里的where子句不知道怎么写
请帮忙
【问题讨论】:
【参考方案1】:类似:
List<PatientDTO> lstChildProf = objService.GetAllPatient()
.Where( l => l.ChildFName == Strings.UCase(Strings.Trim(Txtname.Text))
&& l.ChildName == Strings.UCase(Strings.Trim(txtSurName.Text))
&& l.chiuldMob == Strings.Trim(txtMobile.Text))
.ToList<PatientDTO>();
【讨论】:
错误 14 无法将类型“System.Collections.Generic.IEnumerableList<PatientDTO>
更改为IEnumerable<PatientDTO>
,要么将ToList()
放在该代码的末尾。
@vini,我不知道GetAllPatient()
方法返回的是什么类型,但是你可以把.ToList<PatientDTO>()
放在它的最后作为Arran suggested以上是关于将 SQL 转换为 LINQ 格式的 where 子句的主要内容,如果未能解决你的问题,请参考以下文章
将包含 where、group by、sum 和必须的 MySQL 语句转换为 Linq to Sql
将 SQL 子查询转换为包含 IN、DISTINCT 关键字的 LINQ 格式