Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ef-core-2.0.md #1892

Merged
merged 2 commits into from
Nov 8, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions entity-framework/core/what-is-new/ef-core-2.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,12 @@ public class BloggingContext : DbContext
{
modelBuilder.Entity<Post>().HasQueryFilter(
p => !p.IsDeleted
&& p.TenantId == this.TenantId );
&& p.TenantId == this.TenantId);
}
}
```

We define a model-level filter that implements multi-tenancy and soft-delete for instances of the `Post` Entity Type. Note the use of a DbContext instance level property: `TenantId`. Model-level filters will use the value from the correct context instance (that is, the context instance that is executing the query).
We define a model-level filter that implements multi-tenancy and soft-delete for instances of the `Post` Entity Type. Note the use of a `DbContext` instance-level property: `TenantId`. Model-level filters will use the value from the correct context instance (that is, the context instance that is executing the query).

Filters may be disabled for individual LINQ queries using the IgnoreQueryFilters() operator.

Expand All @@ -114,7 +114,7 @@ public class BloggingContext : DbContext
[DbFunction]
public static int PostReadCount(int blogId)
{
throw new Exception();
throw new NotImplementedException();
}
}
```
Expand All @@ -130,9 +130,9 @@ var query =

A few things to note:

- By convention the name of the method is used as the name of a function (in this case a user defined function) when generating the SQL, but you can override the name and schema during method registration
- Currently only scalar functions are supported
- You must create the mapped function in the database. EF Core migrations will not take care of creating it
- By convention the name of the method is used as the name of a function (in this case a user-defined function) when generating the SQL, but you can override the name and schema during method registration.
- Currently only scalar functions are supported.
- You must create the mapped function in the database. EF Core migrations will not take care of creating it.

### Self-contained type configuration for code first

Expand All @@ -141,11 +141,11 @@ In EF6 it was possible to encapsulate the code first configuration of a specific
``` csharp
class CustomerConfiguration : IEntityTypeConfiguration<Customer>
{
public void Configure(EntityTypeBuilder<Customer> builder)
{
builder.HasKey(c => c.AlternateKey);
builder.Property(c => c.Name).HasMaxLength(200);
}
public void Configure(EntityTypeBuilder<Customer> builder)
{
builder.HasKey(c => c.AlternateKey);
builder.Property(c => c.Name).HasMaxLength(200);
}
}

...
Expand Down Expand Up @@ -208,7 +208,7 @@ EF Core supports automatic generation of key values through a variety of mechani

## Query

### Improved LINQ Translation
### Improved LINQ translation

Enables more queries to successfully execute, with more logic being evaluated in the database (rather than in-memory) and less data unnecessarily being retrieved from the database.

Expand All @@ -218,7 +218,7 @@ This work improves the SQL that is generated for group joins. Group joins are mo

### String interpolation in FromSql and ExecuteSqlCommand

C# 6 introduced String Interpolation, a feature that allows C# expressions to be directly embedded in string literals, providing a nice way of building strings at runtime. In EF Core 2.0 we added special support for interpolated strings to our two primary APIs that accept raw SQL strings: `FromSql` and `ExecuteSqlCommand`. This new support allows C# string interpolation to be used in a 'safe' manner. That is, in a way that protects against common SQL injection mistakes that can occur when dynamically constructing SQL at runtime.
C# 6 introduced String Interpolation, a feature that allows C# expressions to be directly embedded in string literals, providing a nice way of building strings at runtime. In EF Core 2.0 we added special support for interpolated strings to our two primary APIs that accept raw SQL strings: `FromSql` and `ExecuteSqlCommand`. This new support allows C# string interpolation to be used in a "safe" manner. That is, in a way that protects against common SQL injection mistakes that can occur when dynamically constructing SQL at runtime.

Here is an example:

Expand Down Expand Up @@ -265,7 +265,7 @@ Note that Like() comes with an in-memory implementation, which can be handy when

## Database management

### Pluralization hook for DbContext Scaffolding
### Pluralization hook for DbContext scaffolding

EF Core 2.0 introduces a new *IPluralizer* service that is used to singularize entity type names and pluralize DbSet names. The default implementation is a no-op, so this is just a hook where folks can easily plug in their own pluralizer.

Expand Down Expand Up @@ -306,7 +306,7 @@ Significantly augments how providers can interact with the model and simplifies

EF Core 2.0 will now build a different [IModel](https://github.com/aspnet/EntityFramework/blob/master/src/EFCore/Metadata/IModel.cs) for each different provider being used. This is usually transparent to the application. This has facilitated a simplification of lower-level metadata APIs such that any access to *common relational metadata concepts* is always made through a call to `.Relational` instead of `.SqlServer`, `.Sqlite`, etc.

### Consolidated Logging and Diagnostics
### Consolidated logging and diagnostics

Logging (based on ILogger) and Diagnostics (based on DiagnosticSource) mechanisms now share more code.

Expand Down