Skip to content

Commit

Permalink
Consistent 4-space indention (#1898)
Browse files Browse the repository at this point in the history
  • Loading branch information
vanillajonathan authored and ajcvickers committed Nov 5, 2019
1 parent f66d2b8 commit e11e203
Showing 1 changed file with 31 additions and 33 deletions.
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

0 comments on commit e11e203

Please sign in to comment.