Skip to content

Commit

Permalink
Add docs for configuring Azure SQL Database options
Browse files Browse the repository at this point in the history
Fixes #1808
  • Loading branch information
AndriySvyryd committed Nov 10, 2019
1 parent 47ae5ab commit 6f63ee5
Show file tree
Hide file tree
Showing 15 changed files with 175 additions and 34 deletions.
2 changes: 1 addition & 1 deletion entity-framework/core/modeling/index.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: Creating and configuring a model - EF Core
author: rowanmiller
ms.date: 10/27/2016
ms.date: 11/05/2019
ms.assetid: 88253ff3-174e-485c-b3f8-768243d01ee1
uid: core/modeling/index
---
Expand Down
10 changes: 5 additions & 5 deletions entity-framework/core/modeling/relational/indexes.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
title: Indexes (Relational Database) - EF Core
author: rowanmiller
ms.date: 10/27/2016
ms.assetid: 4581e7ba-5e7f-452c-9937-0aaf790ba10a
author: AndriySvyryd
ms.author: ansvyryd
ms.date: 11/05/2019
uid: core/modeling/relational/indexes
---
# Indexes (Relational Database)
Expand Down Expand Up @@ -30,12 +30,12 @@ You can also specify a filter.

[!code-csharp[Main](../../../../samples/core/Modeling/FluentAPI/Relational/IndexFilter.cs?name=Model&highlight=9)]

When using the SQL Server provider EF adds a 'IS NOT NULL' filter for all nullable columns that are part of a unique index. To override this convention you can supply a `null` value.
When using the SQL Server provider EF adds an `'IS NOT NULL'` filter for all nullable columns that are part of a unique index. To override this convention you can supply a `null` value.

[!code-csharp[Main](../../../../samples/core/Modeling/FluentAPI/Relational/IndexNoFilter.cs?name=Model&highlight=10)]

### Include Columns in SQL Server Indexes

You can configure [indexes with included columns](https://docs.microsoft.com/sql/relational-databases/indexes/create-indexes-with-included-columns) to significantly improve query performance when all columns in the query are included in the index as key or non-key columns.

[!code-csharp[Main](../../../../samples/core/Modeling/FluentAPI/Relational/ForSqlServerHasIndex.cs?name=Model)]
[!code-csharp[Main](../../../../samples/core/Modeling/FluentAPI/Relational/IndexInclude.cs?name=Model)]
34 changes: 34 additions & 0 deletions entity-framework/core/providers/sql-server/azure-sql-database.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
title: Microsoft SQL Server Database Provider - Azure SQL Database Options - EF Core
description: How to specify the service tier and performance level for Azure SQL Database with the SQL Server Entity Framework Core Database Provider
author: AndriySvyryd
ms.author: ansvyryd
ms.date: 11/05/2019
uid: core/providers/sql-server/azure-sql-database
---
# Specifying Azure SQL Database Options

>[!NOTE]
> This API is new in EF Core 3.1.
Azure SQL Database provides [a variety of pricing options](https://azure.microsoft.com/pricing/details/sql-database/single/) that are usually configured through the Azure Portal. However if you are managing the schema using [EF Core migrations](xref:core/managing-schemas/migrations/index) you can specify the desired options in the model itself.

You can specify the service tier of the database (EDITION) using [HasServiceTier](/dotnet/api/Microsoft.EntityFrameworkCore.SqlServerModelBuilderExtensions.HasServiceTier):

[!code-csharp[HasServiceTier](../../../../samples/core/SqlServer/AzureDatabase/AzureSqlContext.cs?name=HasServiceTier)]

You can specify the maximum size of the database using [HasDatabaseMaxSize](/dotnet/api/Microsoft.EntityFrameworkCore.SqlServerModelBuilderExtensions.HasDatabaseMaxSize):

[!code-csharp[HasDatabaseMaxSize](../../../../samples/core/SqlServer/AzureDatabase/AzureSqlContext.cs?name=HasDatabaseMaxSize)]

You can specify the performance level of the database (SERVICE_OBJECTIVE) using [HasPerformanceLevel](/dotnet/api/Microsoft.EntityFrameworkCore.SqlServerModelBuilderExtensions.HasPerformanceLevel):

[!code-csharp[HasPerformanceLevel](../../../../samples/core/SqlServer/AzureDatabase/AzureSqlContext.cs?name=HasPerformanceLevel)]

Use [HasPerformanceLevelSql](/dotnet/api/Microsoft.EntityFrameworkCore.SqlServerModelBuilderExtensions.HasPerformanceLevelSql) to configure the elastic pool, since the value is not a string literal:

[!code-csharp[HasPerformanceLevel](../../../../samples/core/SqlServer/AzureDatabase/AzureSqlContext.cs?name=HasPerformanceLevelSql)]


>[!TIP]
> You can find all the supported values in the [ALTER DATABASE documentation](/sql/t-sql/statements/alter-database-transact-sql?view=azuresqldb-current).
11 changes: 6 additions & 5 deletions entity-framework/core/providers/sql-server/index.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
---
title: Microsoft SQL Server Database Provider - EF Core
author: rowanmiller
ms.date: 10/27/2016
ms.assetid: 2e007c82-c6e4-45bb-8129-851b79ec1a0a
description: Documentation for the database provider that allows Entity Framework Core to be used with Microsoft SQL Server
author: AndriySvyryd
ms.author: ansvyryd
ms.date: 11/05/2019
uid: core/providers/sql-server/index
---
# Microsoft SQL Server EF Core Database Provider

This database provider allows Entity Framework Core to be used with Microsoft SQL Server (including SQL Azure). The provider is maintained as part of the [Entity Framework Core Project](https://github.com/aspnet/EntityFrameworkCore).
This database provider allows Entity Framework Core to be used with Microsoft SQL Server (including Azure SQL Database). The provider is maintained as part of the [Entity Framework Core Project](https://github.com/aspnet/EntityFrameworkCore).

## Install

Expand All @@ -28,7 +29,7 @@ Install-Package Microsoft.EntityFrameworkCore.SqlServer
***

> [!NOTE]
> Since version 3.0.0, the provider references Microsoft.Data.SqlClient (previous versions depended on System.Data.SqlClient). If your project takes a direct dependency on SqlClient, make sure it references the correct package.
> Since version 3.0.0, the provider references Microsoft.Data.SqlClient (previous versions depended on System.Data.SqlClient). If your project takes a direct dependency on SqlClient, make sure it references the Microsoft.Data.SqlClient package.
## Supported Database Engines

Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
---
title: Microsoft SQL Server Database Provider - Memory-Optimized Tables - EF Core
author: rowanmiller
ms.date: 10/27/2016
ms.assetid: 2e007c82-c6e4-45bb-8129-851b79ec1a0a
description: How to use Memory-Optimized Tables with the SQL Server Entity Framework Core Database Provider
author: AndriySvyryd
ms.author: ansvyryd
ms.date: 11/05/2019
uid: core/providers/sql-server/memory-optimized-tables
---

# Memory-Optimized Tables support in SQL Server EF Core Database Provider

[Memory-Optimized Tables](https://docs.microsoft.com/sql/relational-databases/in-memory-oltp/memory-optimized-tables) are a feature of SQL Server where the entire table resides in memory. A second copy of the table data is maintained on disk, but only for durability purposes. Data in memory-optimized tables is only read from disk during database recovery. For example, after a server restart.
[Memory-Optimized Tables](/sql/relational-databases/in-memory-oltp/memory-optimized-tables) are a feature of SQL Server where the entire table resides in memory. A second copy of the table data is maintained on disk, but only for durability purposes. Data in memory-optimized tables is only read from disk during database recovery. For example, after a server restart.

## Configuring a memory-optimized table

You can specify that the table an entity is mapped to is memory-optimized. When using EF Core to create and maintain a database based on your model (either with migrations or `Database.EnsureCreated()`), a memory-optimized table will be created for these entities.
You can specify that the table an entity is mapped to is memory-optimized. When using EF Core to create and maintain a database based on your model (either with [migrations](xref:core/managing-schemas/migrations/index) or [EnsureCreated](/dotnet/api/Microsoft.EntityFrameworkCore.Storage.IDatabaseCreator.EnsureCreated)), a memory-optimized table will be created for these entities.

``` csharp
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Blog>()
.ForSqlServerIsMemoryOptimized();
}
```
[!code-csharp[IsMemoryOptimized](../../../../samples/core/SqlServer/InMemory/InMemoryContext.cs?name=IsMemoryOptimized)]
2 changes: 2 additions & 0 deletions entity-framework/toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,8 @@
href: core/providers/sql-server/index.md
- name: Memory-Optimized Tables
href: core/providers/sql-server/memory-optimized-tables.md
- name: Specifying Azure SQL Database Options
href: core/providers/sql-server/azure-sql-database.md
- name: SQLite
items:
- name: Overview
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using Microsoft.EntityFrameworkCore;

namespace EFModeling.FluentAPI.Relational.ForSqlServerHasIndex
namespace EFModeling.FluentAPI.Relational.IndexInclude
{
#region Model
class MyContext : DbContext
Expand Down
36 changes: 27 additions & 9 deletions samples/core/Samples.sln
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,23 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Miscellaneous", "Miscellane
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Modeling", "Modeling", "{CA5046EC-C894-4535-8190-A31F75FDEB96}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Saving", "Saving\Saving.csproj", "{353F06F1-F0E0-4A8F-83AA-7115CD05832D}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Saving", "Saving\Saving.csproj", "{353F06F1-F0E0-4A8F-83AA-7115CD05832D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DataAnnotations", "Modeling\DataAnnotations\DataAnnotations.csproj", "{F583DA77-954C-4C4E-9F46-846CB39208DE}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DataAnnotations", "Modeling\DataAnnotations\DataAnnotations.csproj", "{F583DA77-954C-4C4E-9F46-846CB39208DE}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FluentAPI", "Modeling\FluentAPI\FluentAPI.csproj", "{20E1786B-FA14-4470-8B90-62A0C197E54D}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FluentAPI", "Modeling\FluentAPI\FluentAPI.csproj", "{20E1786B-FA14-4470-8B90-62A0C197E54D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Conventions", "Modeling\Conventions\Conventions.csproj", "{73E054DC-BF55-4717-A729-7FA53382E0EA}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Conventions", "Modeling\Conventions\Conventions.csproj", "{73E054DC-BF55-4717-A729-7FA53382E0EA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestProject", "Miscellaneous\Testing\TestProject\TestProject.csproj", "{F4468750-9480-48E0-AA7A-DE84780AE1C2}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestProject", "Miscellaneous\Testing\TestProject\TestProject.csproj", "{F4468750-9480-48E0-AA7A-DE84780AE1C2}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BusinessLogic", "Miscellaneous\Testing\BusinessLogic\BusinessLogic.csproj", "{60B2C7AF-655F-4709-9E7F-7403E61F3A08}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BusinessLogic", "Miscellaneous\Testing\BusinessLogic\BusinessLogic.csproj", "{60B2C7AF-655F-4709-9E7F-7403E61F3A08}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Logging", "Miscellaneous\Logging\Logging\Logging.csproj", "{D3A5391D-9351-44D6-8122-2821C6E4BD62}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Querying", "Querying\Querying.csproj", "{7DEB577A-52B8-4475-A109-689FD515AEEA}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Querying", "Querying\Querying.csproj", "{7DEB577A-52B8-4475-A109-689FD515AEEA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConnectionResiliency", "Miscellaneous\ConnectionResiliency\ConnectionResiliency.csproj", "{73D58479-A7E6-4867-8A73-0E07E96C6117}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConnectionResiliency", "Miscellaneous\ConnectionResiliency\ConnectionResiliency.csproj", "{73D58479-A7E6-4867-8A73-0E07E96C6117}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DynamicModel", "DynamicModel\DynamicModel.csproj", "{70D00673-084C-40B7-B0F1-67498593F8EE}"
EndProject
Expand All @@ -47,6 +47,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Cosmos", "Cosmos\Cosmos.csp
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EFGetStarted", "GetStarted\EFGetStarted.csproj", "{14A4E71C-57EB-4CB8-BBC3-C35CE4707E52}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SqlServer", "SqlServer\SqlServer.csproj", "{80756004-3664-481A-879F-E1A261328758}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -339,6 +341,22 @@ Global
{14A4E71C-57EB-4CB8-BBC3-C35CE4707E52}.Release|x64.Build.0 = Release|Any CPU
{14A4E71C-57EB-4CB8-BBC3-C35CE4707E52}.Release|x86.ActiveCfg = Release|Any CPU
{14A4E71C-57EB-4CB8-BBC3-C35CE4707E52}.Release|x86.Build.0 = Release|Any CPU
{80756004-3664-481A-879F-E1A261328758}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{80756004-3664-481A-879F-E1A261328758}.Debug|Any CPU.Build.0 = Debug|Any CPU
{80756004-3664-481A-879F-E1A261328758}.Debug|ARM.ActiveCfg = Debug|Any CPU
{80756004-3664-481A-879F-E1A261328758}.Debug|ARM.Build.0 = Debug|Any CPU
{80756004-3664-481A-879F-E1A261328758}.Debug|x64.ActiveCfg = Debug|Any CPU
{80756004-3664-481A-879F-E1A261328758}.Debug|x64.Build.0 = Debug|Any CPU
{80756004-3664-481A-879F-E1A261328758}.Debug|x86.ActiveCfg = Debug|Any CPU
{80756004-3664-481A-879F-E1A261328758}.Debug|x86.Build.0 = Debug|Any CPU
{80756004-3664-481A-879F-E1A261328758}.Release|Any CPU.ActiveCfg = Release|Any CPU
{80756004-3664-481A-879F-E1A261328758}.Release|Any CPU.Build.0 = Release|Any CPU
{80756004-3664-481A-879F-E1A261328758}.Release|ARM.ActiveCfg = Release|Any CPU
{80756004-3664-481A-879F-E1A261328758}.Release|ARM.Build.0 = Release|Any CPU
{80756004-3664-481A-879F-E1A261328758}.Release|x64.ActiveCfg = Release|Any CPU
{80756004-3664-481A-879F-E1A261328758}.Release|x64.Build.0 = Release|Any CPU
{80756004-3664-481A-879F-E1A261328758}.Release|x86.ActiveCfg = Release|Any CPU
{80756004-3664-481A-879F-E1A261328758}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -350,12 +368,12 @@ Global
{73E054DC-BF55-4717-A729-7FA53382E0EA} = {CA5046EC-C894-4535-8190-A31F75FDEB96}
{F4468750-9480-48E0-AA7A-DE84780AE1C2} = {4E2B02EE-0C76-42D6-BA0A-337D7680A5D6}
{60B2C7AF-655F-4709-9E7F-7403E61F3A08} = {4E2B02EE-0C76-42D6-BA0A-337D7680A5D6}
{D3A5391D-9351-44D6-8122-2821C6E4BD62} = {85AFD7F1-6943-40FE-B8EC-AA9DBB42CCA6}
{73D58479-A7E6-4867-8A73-0E07E96C6117} = {85AFD7F1-6943-40FE-B8EC-AA9DBB42CCA6}
{70D00673-084C-40B7-B0F1-67498593F8EE} = {CA5046EC-C894-4535-8190-A31F75FDEB96}
{FD21B5E9-B1D9-4788-A313-5C0CDA30D1D7} = {CA5046EC-C894-4535-8190-A31F75FDEB96}
{802E31AD-2F1E-41A1-A662-5929E2626601} = {CA5046EC-C894-4535-8190-A31F75FDEB96}
{63685B9A-1233-4B44-AAC1-8DDD4B16B65D} = {CA5046EC-C894-4535-8190-A31F75FDEB96}
{D3A5391D-9351-44D6-8122-2821C6E4BD62} = {85AFD7F1-6943-40FE-B8EC-AA9DBB42CCA6}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {20C98D35-54EF-46A6-8F3B-1855C1AE4F70}
Expand Down
33 changes: 33 additions & 0 deletions samples/core/SqlServer/AzureDatabase/AzureSqlContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using Microsoft.EntityFrameworkCore;

namespace SqlServer.AzureDatabase
{
public class AzureSqlContext : DbContext
{
public DbSet<Blog> Blogs { get; set; }

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlServer("Server=tcp:[serverName].database.windows.net;Database=myDataBase;User ID=[Login]@[serverName];Password=myPassword];Trusted_Connection=False;Encrypt=True;");
}

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
#region HasServiceTier
modelBuilder.HasServiceTier("BusinessCritical");
#endregion

#region HasDatabaseMaxSize
modelBuilder.HasDatabaseMaxSize("2 GB");
#endregion

#region HasPerformanceLevelSql
modelBuilder.HasPerformanceLevelSql("ELASTIC_POOL ( name = myelasticpool )");
#endregion

#region HasPerformanceLevel
modelBuilder.HasPerformanceLevel("BC_Gen4_1");
#endregion
}
}
}
8 changes: 8 additions & 0 deletions samples/core/SqlServer/AzureDatabase/Blog.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace SqlServer.AzureDatabase
{
public class Blog
{
public int BlogId { get; set; }
public string Url { get; set; }
}
}
8 changes: 8 additions & 0 deletions samples/core/SqlServer/InMemory/Blog.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace SqlServer.InMemory
{
public class Blog
{
public int BlogId { get; set; }
public string Url { get; set; }
}
}
16 changes: 16 additions & 0 deletions samples/core/SqlServer/InMemory/InMemoryContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Microsoft.EntityFrameworkCore;

namespace SqlServer.InMemory
{
public class InMemoryContext : DbContext
{
public DbSet<Blog> Blogs { get; set; }

#region IsMemoryOptimized
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Blog>().IsMemoryOptimized();
}
#endregion
}
}
6 changes: 6 additions & 0 deletions samples/core/SqlServer/InMemory/Sample.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace SqlServer.InMemory
{
public class Sample
{
}
}
9 changes: 9 additions & 0 deletions samples/core/SqlServer/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace SqlServer
{
public class Program
{
static void Main()
{
}
}
}
12 changes: 12 additions & 0 deletions samples/core/SqlServer/SqlServer.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.0-preview2.19525.5" />
</ItemGroup>

</Project>

0 comments on commit 6f63ee5

Please sign in to comment.