惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Martin Fowler
Martin Fowler
有赞技术团队
有赞技术团队
博客园_首页
H
Help Net Security
GbyAI
GbyAI
aimingoo的专栏
aimingoo的专栏
V
Visual Studio Blog
The Cloudflare Blog
腾讯CDC
Jina AI
Jina AI
Last Week in AI
Last Week in AI
月光博客
月光博客
博客园 - 叶小钗
Google DeepMind News
Google DeepMind News
B
Blog RSS Feed
Blog — PlanetScale
Blog — PlanetScale
人人都是产品经理
人人都是产品经理
Engineering at Meta
Engineering at Meta
Y
Y Combinator Blog
Hugging Face - Blog
Hugging Face - Blog
博客园 - 聂微东
爱范儿
爱范儿
N
Netflix TechBlog - Medium
F
Fortinet All Blogs

博客园 - 咒语

Azure OAuth2 PostMan 授权代码 跨线程 操作Winform 主UI时的扩展方法 每当双11来时,商家与京东的那些骚操作,京东30天保价不能信 Microsoft.Extensions.DependencyInjection 阅读笔记 EasyToLearnDesignPattern 软件开发中的版本号 The specified type member 'Date' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported. ABP项目依赖图,根据自已生在的Demo项目分析而得 学习ELk之----02. Elastic Search操作入门 学习ELK之----01.建立ELK测试项目 一目了然呀的VS2017 Live Test 在Hyper-V上安装RemixOS 的Android模拟器 配置Asp.Net Web项目NLog配置文件的位置 配置WinRM的Https 测试EntityFramework,Z.EntityFramework.Extensions,原生语句在不同的查询中的表现。原来池化与非池化设定是有巨大的影响的。 消费RabbitMQ时的注意事项,如何禁止大量的消息涌到Consumer RabbitMQ调试与测试工具-v1.0.1 -提供下载测试与使用 安装TFS2015后启用生成功能 log4net在Realse下有个好大的坑呀。
C#中关于表达式与委托在EF中的不同表现总结
咒语 · 2018-06-28 · via 博客园 - 咒语

2018-06-28 09:58  咒语  阅读(513)  评论()    收藏  举报

Func<Invoice, bool> func = x => x.State == InvoiceState.Created;
Expression<Func<Invoice, bool>> expression = x => x.State == InvoiceState.Created;

            using (var db = new CrmDbContext())
            {
                var q1 = db.Invoices.Where(func); //全部查询出来后筛选
                var q2 = db.Invoices.Where(expression); //直接延迟到Count时执行

                var query = db.Invoices.AsQueryable();
                var qq1 = query.Where(func);//全部查询出来后筛选
                var qq2 = query.Where(expression); //直接延迟到Count时执行

                Console.WriteLine($"q1:{q1.Count()}");
                Console.WriteLine($"q2:{q2.Count()}");
                Console.WriteLine($"qq1:{qq1.Count()}");
                Console.WriteLine($"qq2:{qq2.Count()}");
            }

看到上面的不同表现结果,知道该怎么写了吧!

简单来说:委托的查询是针对一个(已存在的)集合的,而表达式是用来表述条件。