1.LINQ过滤数据
var query = from person in context.People where person.FirstName.StartsWith("a") select person; var methodQuery = context.People.Where(p => p.FirstName.StartsWith("a"));
两种不同的写法,效果一样。
- 多条件组合查找
var query = from person in context.People where person.FirstName.StartsWith("a") && person.LastName.EndsWith("b") select person; var methodQuery = context.People.Where(p => p.FirstName.StartsWith("a") && p.LastName.EndsWith("b"));
- 对查找结果排序
var query = from person in context.People where person.FirstName.StartsWith("a") && person.LastName.EndsWith("b") orderby person.FirstName,person.LastName select person; var methodQuery = context.People .Where(p => p.FirstName.StartsWith("a") && p.LastName.EndsWith("b")) .OrderBy(p => p.FirstName) .ThenBy(p => p.LastName);
时间: 2024-12-20 19:43:42