Home  >  Article  >  Backend Development  >  Detailed introduction to .NET Core 2.0 Preview2

Detailed introduction to .NET Core 2.0 Preview2

零下一度
零下一度Original
2018-05-15 15:27:342032browse

This article mainly introduces the relevant content of .NET Core 2.0 Preview2 release summary in detail, which has certain reference value. Interested friends can refer to it

Preface

About the new features of ASP.NET Core 2.0, you can check out this blog of mine. This article is about some improvements in Priview2.

.NET Core 2.0 - Preview2

Azure improvements
Docker images moved to Debian Stretch
Fixes and support for macOS High Sierra
Quality and Performance improvement
dotnet restore will be called implicitly during dotnet run, publish, build
.NET Standard library can reference .NET Framework library
.NET Standard NuGet package nuspec no longer needs to add dependencies for NETStandard.Library

ASP.NET Core 2.0 - Preview2

Updated the Visual Studio templates and added templates for SPA projects. Including (Angular, React.js, React.js and Redux), etc.


#Added a template for creating a new ASP.NET Core project in Visual Studio 2017 using the .NET Framework framework.


Kestrel adds some configuration options, including (MaxConcurrentConnections, MaxRequestBodySize, RequestBodyMinimumDataRate), etc.

Razor supports C# 7.1. This configuration can be enabled by specifying 0f3802d193a0548f1e8805d4090d60c7latesta1ce00407b3b68bab908063fc8f7cbae in csproj.
For FileStreamResult in MVC Action, the Http header of FileContentResult increases the supported range. ETag, LastUpdate, etc. can now be added.

Added two new filters (IPageFilter, IAsyncPageFilter) about Razor Page.
Regarding the Identity related services in Priview 1 and the configuration of HTTPS, they have been cut off. They still need time to polish and wait for future release.

Entity Framework Core 2.0 - Preview2

New NuGet packages and toolkits (Microsoft.EntityFrameworkCore.Tools.DotNet)
##FromSql and ExecuteSqlCommand #StringInterpolation, the SQL they generate will be automatically parameterized.

var city = "London";
var contactTitle = "Sales Representative";

using (var context = CreateContext())
{
 context.Customers
 .FromSql($@"
 SELECT *
 FROM Customers
 WHERE City = {city}
 AND ContactTitle = {contactTitle}")
 .ToArray();
}

Generated SQL:

@p0='London' (Size = 4000)
@p1='Sales Representative' (Size = 4000)

SELECT *
FROM Customers
WHERE City = @p0
 AND ContactTitle = @p1

Entity type automatically splits the table (improving the function in Priview1), only one table will be created below.

modelBuilder.Entity<Order>().OwnsOne(
 p => p.OrderDetails,
 cb =>
 {
 cb.OwnsOne(c => c.BillingAddress);
 cb.OwnsOne(c => c.ShippingAddress);
 });

public class Order
{
 public int Id { get; set; }
 public OrderDetails OrderDetails { get; set; }
}

public class OrderDetails
{
 public Address BillingAddress { get; set; }
 public Address ShippingAddress { get; set; }
}

public class Address
{
 public string Street { get; set; }
 public string City { get; set; }
}

Database function mapping, you can use functions defined in the database in your code. Note that the return value can only be a single (scalar).

public class BloggingContext : DbContext
{
 [DbFunction] // 添加这个标记,静态方法
 public static int PostReadCount(int blogId)
 {
 throw new Exception();
 }
}

The PostReadCount function defined in the database will be called. The function must be created manually and EF will not automatically generate it.

var query =
 from p in context.Posts
 where BloggingContext.PostReadCount(p.Id) > 5
 select p;

Other improvements (compatibility, outdated API, etc.)

The above is the detailed content of Detailed introduction to .NET Core 2.0 Preview2. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn