Linq查询语句
程序员文章站
2022-07-04 10:20:48
...
LINQ(Language Integrated Query)语言集成查询是一组用于c#和Visual Basic语言的扩展。它允许编写C#或者Visual Basic代码以操作内存数据的方式,查询数据库。
语法:
查询数据列表集合ToList
List<SelectVo> lists = (from tb in Model.SYS
select new SelectVo
{
id = tb. ID,
text = tb.Name
}).ToList();
查询单行数Single
var teacher = (from tbTeacher in Model.PW_Teacher
where tbTeacher.UserID == intUserId
select tbTeacher).Single();
去重复Distinct
List<SelectVo> lists = (from tb in Model.SYS
select new SelectVo
{
id = tb. ID,
text = tb.Name
}) .Distinct().ToList();;
排序
var list = from tb in Model.SYS
orderby tb. ID
select tb;
子查询
List< Select> list= (from tb in Model.SYS_Modular
orderby tb.ModularID
select new Select
{
ModularID = tb.ModularID,
ModularName = tb.ModularName,
ModularDetailVos = (from tb in Model.SYS_ModularDetail
where tb.ModularID == ID
orderby tb.ModularDetailID
select new ModularDetailVo
{
id = tbModularDetail.ModularDetailID, OpType = tbOpType.OpType.Trim()
}).ToList()
}).ToList();