. net core 2.0 preview2 release summary

Time:2021-7-17

preface

For the new features of asp.net core 2.0, please see myThis blog。 This article is an improvement on priview2.

.NET Core 2.0 – Preview2

Improvement of azure
Docker image transferred to Debian stretch
Fix and support MacOS High Sierra
qualityandperformanceThe improvement of
dotnet restoreIt will be called implicitly in dotnet run, publish, build
. net standard library can refer to. Net framework library
For. Net standard nuget package, nuspec no longer needs to be addedNETStandard.LibraryIt’s a dependency

ASP.NET Core 2.0 – Preview2

The template of visual studio is updated and the template of spa project is added. Including (angular, react.js, react.js and Redux), etc.

Added a template for creating a new asp.net core project in Visual Studio 2017 to use the. Net framework.

Kestrel added some configuration options, including (maxconcurrent connections, maxrequest bodysize, request bodyminimum DataRate), etc.

Razor supports C # 7.1. This configuration can be specified in csproj<LangVersion>latest</ LangVersion>Turn it on.
For the filestreamresult in MVC action, the HTTP header of filecontentresult increases the scope of support. Now you can add Etag, lastupdate, etc.

Two new filters (ipagefilter, iasyncpagefilter) for razor page are added.
As for identity related services in Priview 1, the configuration of HTTPS has been cut off. They still need time to polish and wait for future release.

Entity Framework Core 2.0 – Preview2

New nuget package and Toolkit (Microsoft. Entityframeworkcore. Tools. Dotnet)
String interpolation in fromsql and executesqlcommand, the SQL generated by them will be parameterized automatically.


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

using (var context = CreateContext())
{
 context.Customers
 .FromSql([email protected]"
 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

The entity type automatically splits the table (perfecting the function in priview1). Only one table will be created.


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 the functions defined in the database in the code, note that the return value can only be a single (scalar).

public class BloggingContext : DbContext
{
 [dbfunction] // add this tag, static method
 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 be generated automatically.


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

Other improvements (compatibility, outdated APIs, etc.)

The above is the whole content of this article, I hope to help you learn, and I hope you can support developer more.