linq to sql语句各参数什么意思:比如:var q = from c in db.Customers

where c.City == "London" select c; foreach (var v in q) 这句话呢? {}
2025-04-30 06:13:57
推荐回答(2个)
回答1:

var q = from c in db.Customers where c.City == "London" select c
等价于SQL语句
select * from db.Customers c where c.City = "London"
然后把记录集赋给变量q

foreach (var v in q)
表示记录集q里的每一条记录v要执行下马{}里的操作

回答2:

LINQ是将SQL语句倒写的。
你可以看成 select c from customers where c.city = 'London'
也就是查找客户表中城市名称为:London的客户。然后循环对这些客户做操作。