2.0.0-priview1-final, so this article is mainly about some instructions for this version.
mysql tutorial"
// 安装 PM> install-package Microsoft.EntityFrameworkCore.SqlServer -Pre -Version 2.0.0-preview1-final // 升级 PM> update-package Microsoft.EntityFrameworkCore.SqlServer -Pre -Version 2.0.0-preview1-finalToolkit
// 直接修改 CSPROJ 文件 <ItemGroup> <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0-preview1-final" /> </ItemGroup> // 或者通过以下命令 PM> update-package Microsoft.EntityFrameworkCore.Tools -Pre -Version 2.0.0-preview1-finalEF Core 2.0 New FeaturesImproved LINQ Translation
- Avoid creating unnecessary subqueries
- Some commands will switch to the client for execution
- Only a few requests will retrieve all columns of the table
- Sometimes without appropriate filter conditions, a single LINQ query is converted into N+1 queries.
var aCustomers = from c in context.Customers where EF.Functions.Like(c.Name, "a%"); select c;Separate entities and tablesWhat does it mean to separate entities and tables? In the past, a database table would be mapped to an entity object in EF, that is, there was a one-to-one correspondence between the table and the entity. Then in version 2.0, it is allowed to map some related entities to a table, and EF will maintain these instances or reference relationships.
modelBuilder.Entity<Customer>() .OwnsOne(c => c.WorkAddress);public class Customer { public int CustomerId { get; set; } public Address WorkAddress { get; set; } }public class Address { public string Line { get; set; } public string PostalOrZipCode { get; set; } public string StateOrProvince { get; set; } public string CityOrTown { get; internal set; } }When generating a database table,
Customer and
Address will be generated as one table.
public class BloggingContext : DbContext { public DbSet<Blog> Blogs { get; set; } public DbSet<Post> Posts { get; set; } public int TenantId {get; set; } protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity<Post>() .HasQueryFilter(p => !p.IsDeleted && p.TenantId == this.TenantId ); } }This filter condition will be automatically applied when querying type data through direct query or navigation properties (
Include()). Of course you can use
IgnoreQueryFilters() to disable this global filter in the query.
on every request. In EF Core 2.0, a new way of injecting a custom DbContext is introduced, which explicitly uses an instance pool to inject it into the container.
services.AddDbContextPool<BloggingContext>( options => options.UseSqlServer(connectionString));
Using this method, when the Controller requests a DbContext instance, it will first check whether there is an available instance in the pool. Once the request is processed, any state attached to the instance will be reset. , and then the instance is returned to the pool.
This concept is somewhat similar to the database connection pool in ADO.NET, which has the advantage of saving the cost of initializing a DbContext instance. Many ASP.NET Core applications can use this approach to gain performance improvements.
Manually compiled queries
In previous versions of EF and Linq to SQL, there was an API for manually or explicitly compiling queries, which allowed applications to cache translated queries so that they Can be compiled once and executed multiple times.
Although EF Core can automatically compile and cache queries based on query expressions, this mechanism can obtain a small query performance improvement by bypassing hash calculations or caching, allowing applications to use delegates that have already been called. Query passed by chain compilation.
private static Func<CustomerContext, int, Customer> _customerById = EF.CompileQuery((CustomerContext db, int id) => db.Customers .Include(c => c.Address) .Single(c => c.Id == id)); ...using (var db = new CustomerContext()) { var customer = _customerById(db, 147); }
Others
EF Core 2.0 will also make some major adjustments to some logging and diagnostic infrastructure, as well as integration with Azure Application Insights.
The addition of Lazy Loading (lazy loading) function is still under discussion, and this function may be added in EF Core 2.1.
The above is the detailed content of EF Core 2.0 new features. For more information, please follow other related articles on the PHP Chinese website!

PHP8.3发布:新特性一览随着技术的不断发展和需求的不断变化,编程语言也在不断更新和改进。作为一种广泛应用于网络开发的脚本语言,PHP一直在不断进步,为开发者提供更强大和高效的工具。最近发布的PHP8.3版本带来了许多期待已久的新特性和改进,下面让我们来看一下这些新特性的一览。非空属性的初始化在过去的PHP版本中,如果一个类的属性没有被明确赋值,它的值

深入解析PHP8的新特性,助您掌握最新技术随着时间的推移,PHP编程语言一直在不断演进和改进。最近发布的PHP8版本为开发者提供了许多令人兴奋的新特性和改进,为我们的开发工作带来了更多便利和效率。在本文中,我们将深入解析PHP8的新特性,并提供具体的代码示例,旨在帮助您更好地掌握这些最新的技术。JIT编译器PHP8引入了JIT(Just-In-Time)编

PHP8.1引入的新的Redis扩展随着互联网的快速发展,大量的数据需要进行存储和处理。为了提高数据处理的效率和性能,缓存成为了一个不可或缺的部分。而在PHP开发中,Redis作为一种高性能的键值对存储系统,被广泛应用于缓存和数据存储的场景。为了进一步提升Redis在PHP中的使用体验,PHP8.1引入了新的Redis扩展,本文将介绍这一扩展的新增功能,并给

CSS3的新特性一览:如何使用CSS3实现过渡效果CSS3作为CSS的最新版本,在众多新特性中,最有趣和实用的应该是过渡效果(transition)。过渡效果可以让我们的页面在交互时更加平滑、漂亮,给用户带来良好的视觉体验。本文将介绍CSS3过渡效果的基本用法,并附带相应的代码示例。transition-property属性:指定需要过渡的CSS属性过渡效果

php8新特性有JIT 编译器、类型推导、命名参数、联合类型、属性、错误处理改进、异步编程支持、新的标准库函数和匿名类的扩展等。详细介绍:1、JIT编译器,PHP8引入了JIT编译器,这是一个重要的性能改进,JIT编译器可以对一些高频执行的代码进行实时编译和优化,从而提高运行速度;2、类型推导,PHP8引入了类型推导功能,允许开发者在声明变量时自动推导出变量的类型等等。

CSS3的新特性一览:如何使用CSS3实现水平居中布局在网页设计和布局中,水平居中布局是一项常见的需求。过去,我们经常使用复杂的JavaScript或CSS技巧实现此目的。然而,CSS3引入了一些新的特性,使得水平居中布局更加简单和灵活。本文将介绍一些CSS3的新特性,并提供一些代码示例,演示如何使用CSS3实现水平居中布局。一、使用flexbox布局fle

go语言的新特性有:1、Go模块,用于管理Go语言项目的依赖关系;2、错误处理,增加了一个新的错误类型error,使得错误处理更加灵活和简洁;3、上下文包,用于在goroutine之间传递请求范围的值;4、嵌入,即一个结构体可以嵌入到另一个结构体中;5、同步包,更好地控制goroutine之间的同步和通信;6、错误值,更好地区分不同类型的错误;7、泛型,让开发者编写更灵活。

PHP8作为最新版本的PHP编程语言,引入了许多新的特性和改进,在底层开发原理方面做了一些重要的改变。本文将深入探讨PHP8的底层开发原理,并分析如何利用新特性提高代码性能和可靠性。首先,我们来了解一下PHP8的一些重要的底层开发原理。PHP8引入了JIT(Just-In-Time)编译器,这是一个动态编译器,可以将PHP代码即时转换为本地机器码,并在执行时


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

WebStorm Mac version
Useful JavaScript development tools

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)
