[翻译 EF Core in Action 2.3] 理解EF Core数据库查询

Entity Framework Core in Action

Entityframework Core in action是 Jon P smith 所著的关于Entityframework Core 书籍。原版地址. 是除了官方文档外另一个学习EF Core的不错途径, 书中由浅入深的讲解的EF Core的相关知识。因为没有中文版,所以本人对其进行翻译。 预计每两天一篇更新 PS: 翻译难免限于本人水平有不准确的地方,建议英文水平不错的同学直接查看原版,有不足的地方欢迎指正

第一部分目录导航

理解EF Core数据库查询

现在我们去查看如何使用EF Core查询数据库了. 图2.7展示了一个示例查询,其中包含三个重要的部分

832799-20190426155244552-1571383791.png

  • 注: 如果你熟悉EF 6.x或LINQ,可以跳过本节内容

图2.7中展示了由几个方法组成的一行代码,它们是函数式编程的风格,这样的风格在逻辑上更加直观,更容易阅读. 下面描述代码的三个部分

应用程序数据库上下文的属性访问

代码的第一部分通过EF Core连接到数据库, 引用数据库表的最常用的方法是通过数据库上下文的DbSet属性

在本章都是使用数据库上下文的属性访问数据库表,在后面的章节会介绍到访问类或属性的其他方法,思想基本是一样的. 都需要通过EF Core连接到数据库开始

一系列的LINQ/ EF Core 命令

这部分是一组LINQ或EF Core方法,由它们构造查询条件,根据业务LINQ查询语句可能会变得非常复杂. 本章从最简单的查询示例开始,在后面会介绍到构建复杂的查询语句

执行查询命令

代码的最后一部分很重要,在执行查询命令之前,LINQ被保存为一系列的命令,它并没有在数据上执行. EF Core将LINQ查询的每一个方法转换为正确的SQL在数据库中执行. 在EF Core中查询只有在查询方法调用时才会执行,例如ToList()

转载于:https://www.cnblogs.com/LiangSW/p/10774733.html

Summary Entity Framework Core in Action teaches you how to access and update relational data from .NET applications. Following the crystal-clear explanations, real-world examples, and around 100 diagrams, you'll discover time-saving patterns and best practices for security, performance tuning, and unit testing. Purchase of the print book includes a free eBook in PDF, Kindle, and ePub formats from Manning Publications. About the Technology There's a mismatch in the way OO programs and relational databases represent data. Enti ty Framework is an object-relational mapper (ORM) that bridges this gap, making it radically easier to query and write to databases from a .NET application. EF creates a data model that matches the structure of your OO code so you can query and write to your database using standard LINQ commands. It will even automatically generate the model from your database schema. About the Book Using crystal-clear explanations, real-world examples, and around 100 diagrams, Entity Framework Core in Action teaches you how to access and update relational data from .NET applications. You'l start with a clear breakdown of Entity Framework, long with the mental model behind ORM. Then you'll discover time-saving patterns and best practices for security, performance tuning, and even unit testing. As you go, you'll address common data access challenges and learn how to handle them with Entity Framework. What's Inside Querying a relational database with LINQ Using EF Core in business logic Integrating EF with existing C# applications Applying domain-driven design to EF Core Getting the best performance out of EF Core Covers EF Core 2.0 and 2.1
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值