using Demo.Data; using Demo.Domain; using Microsoft.EntityFrameworkCore; using System; using System.Linq; namespace Demo.App { class Program { static void Main(string[] args) { using var context = new DemoContext(); //var italy = "Italy"; //var leagues = context.Leagues // .Where(x=>x.Country== italy)//变量参数化查询,直接用值就不是 // .ToList(); ////var leagues2 = (from lg in context.Leagues where lg.Country== "Italy" select lg).ToList(); //foreach (var league in leagues)//context.Leagues //{ // Console.WriteLine(league.Name); //} //var leagues = context.Leagues // .Where(x => x.Country.Contains("e"))// 输出 [Country] CHARINDEX(N'e', [l].[Country]) > 0 // .ToList(); ////var leagues2 = (from lg in context.Leagues where lg.Country== "Italy" select lg).ToList(); //foreach (var league in leagues)//context.Leagues //{ // Console.WriteLine(league.Name); //} var leagues = context.Leagues .Where(x => EF.Functions.Like(x.Country,"%e%"))// 输出[Country] LIKE N'%e%' .ToList(); //var leagues2 = (from lg in context.Leagues where lg.Country== "Italy" select lg).ToList(); foreach (var league in leagues)//context.Leagues { Console.WriteLine(league.Name); } //ToList() //First() 第一个,没有会报错 //FirstOrDefault 第一个,没有返回默认值 //Single SingleOrDefault Last() LastOrDefault() 一个 最后一个必须排序,否则报错 //Count() LongCount() Min() Max() Average() Sum() 总数 Long类型总数 最大 平均 求和 //Find 寻找 //异步版本 //ToListAsync() //... Console.ReadKey(); } } }