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

Consistent 4-space indention #1898

Merged
merged 1 commit into from
Nov 5, 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
64 changes: 31 additions & 33 deletions entity-framework/core/what-is-new/ef-core-3.0/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ This type of client-side execution is desirable in some situations, but in many
For example, if EF Core 2.2 couldn't translate a predicate in a `Where()` call, it executed an SQL statement without a filter, transferred all the rows from the database, and then filtered them in-memory:

``` csharp
var specialCustomers =
context.Customers
var specialCustomers = context.Customers
.Where(c => c.Name.StartsWith(n) && IsSpecialCustomer(c));
```

Expand All @@ -43,8 +42,7 @@ When EF Core 3.0 detects expressions that can't be translated anywhere else in t
To evaluate a predicate condition on the client as in the previous example, developers now need to explicitly switch evaluation of the query to LINQ to Objects:

``` csharp
var specialCustomers =
context.Customers
var specialCustomers = context.Customers
.Where(c => c.Name.StartsWith(n))
.AsEnumerable() // switches to LINQ to Objects
.Where(c => IsSpecialCustomer(c));
Expand Down Expand Up @@ -74,13 +72,13 @@ Asynchronous query results are now exposed using the new standard `IAsyncEnumera

``` csharp
var orders =
from o in context.Orders
where o.Status == OrderStatus.Pending
select o;
from o in context.Orders
where o.Status == OrderStatus.Pending
select o;

await foreach(var o in orders.AsAsyncEnumerable())
{
Process(o);
Process(o);
}
```

Expand All @@ -95,10 +93,10 @@ For example, in the following class, properties marked as of type `string?` will
``` csharp
public class Customer
{
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string? MiddleName { get; set; }
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string? MiddleName { get; set; }
}
```

Expand All @@ -115,24 +113,24 @@ For example, to manipulate command text, you can create an `IDbCommandIntercepto
``` csharp
public class HintCommandInterceptor : DbCommandInterceptor
{
public override InterceptionResult ReaderExecuting(
DbCommand command,
CommandEventData eventData,
InterceptionResult result)
{
// Manipulate the command text, etc. here...
command.CommandText += " OPTION (OPTIMIZE FOR UNKNOWN)";
return result;
}
public override InterceptionResult ReaderExecuting(
DbCommand command,
CommandEventData eventData,
InterceptionResult result)
{
// Manipulate the command text, etc. here...
command.CommandText += " OPTION (OPTIMIZE FOR UNKNOWN)";
return result;
}
}
```

And register it with your `DbContext`:

``` csharp
services.AddDbContext(b => b
.UseSqlServer(connectionString)
.AddInterceptors(new HintCommandInterceptor()));
.UseSqlServer(connectionString)
.AddInterceptors(new HintCommandInterceptor()));
```

## Reverse engineering of database views
Expand All @@ -151,16 +149,16 @@ And the tool will now automatically scaffold types for views and tables without
``` csharp
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Names>(entity =>
{
entity.HasNoKey();
entity.ToView("Names");
});

modelBuilder.Entity<Things>(entity =>
{
entity.HasNoKey();
});
modelBuilder.Entity<Names>(entity =>
{
entity.HasNoKey();
entity.ToView("Names");
});

modelBuilder.Entity<Things>(entity =>
{
entity.HasNoKey();
});
}
```

Expand Down