Skip to content

Commit 1072ea3

Browse files
CopilotAndriySvyryd
andcommitted
Move ConfigureDbContext sample code to main project and remove separate sample directory
Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
1 parent 52ec51e commit 1072ea3

4 files changed

Lines changed: 11 additions & 22 deletions

File tree

entity-framework/core/dbcontext-configuration/index.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ Starting with EF Core 9.0, you can use <xref:Microsoft.Extensions.DependencyInje
112112
113113
var serviceProvider = services.BuildServiceProvider();
114114
-->
115-
[!code-csharp[BasicConfigureDbContext](../../../samples/core/Miscellaneous/ConfiguringDbContext/ConfigureDbContextSample/Program.cs?name=BasicConfigureDbContext)]
115+
[!code-csharp[BasicConfigureDbContext](../../../samples/core/Miscellaneous/ConfiguringDbContext/ConfigureDbContextSample.cs?name=BasicConfigureDbContext)]
116116

117117
### Provider-specific configuration without connection strings
118118

@@ -130,7 +130,7 @@ To apply provider-specific configuration you can use provider-specific configura
130130
131131
var serviceProvider = services.BuildServiceProvider();
132132
-->
133-
[!code-csharp[ProviderSpecificConfiguration](../../../samples/core/Miscellaneous/ConfiguringDbContext/ConfigureDbContextSample/Program.cs?name=ProviderSpecificConfiguration)]
133+
[!code-csharp[ProviderSpecificConfiguration](../../../samples/core/Miscellaneous/ConfiguringDbContext/ConfigureDbContextSample.cs?name=ProviderSpecificConfiguration)]
134134

135135
### ConfigureDbContext and AddDbContext precedence
136136

@@ -152,7 +152,7 @@ For non-conflicting options (like adding logging, interceptors, or other setting
152152
153153
var serviceProvider = services.BuildServiceProvider();
154154
-->
155-
[!code-csharp[ConfigurationComposition](../../../samples/core/Miscellaneous/ConfiguringDbContext/ConfigureDbContextSample/Program.cs?name=ConfigurationComposition)]
155+
[!code-csharp[ConfigurationComposition](../../../samples/core/Miscellaneous/ConfiguringDbContext/ConfigureDbContextSample.cs?name=ConfigurationComposition)]
156156

157157
For conflicting options, the last configuration wins. See [breaking changes in EF Core 8.0](xref:core/what-is-new/ef-core-8.0/breaking-changes#AddDbContext) for more information about this behavior change.
158158

samples/core/Miscellaneous/ConfiguringDbContext/ConfigureDbContextSample/Program.cs renamed to samples/core/Miscellaneous/ConfiguringDbContext/ConfigureDbContextSample.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#nullable enable
2+
13
using System;
24
using System.Linq;
35
using Microsoft.EntityFrameworkCore;
@@ -21,9 +23,9 @@ public class Blog
2123
public string? Content { get; set; }
2224
}
2325

24-
public class Program
26+
public static class ConfigureDbContextExamples
2527
{
26-
public static void Main(string[] args)
28+
public static void Run()
2729
{
2830
BasicConfigureDbContextExample();
2931
ProviderSpecificConfigurationExample();

samples/core/Miscellaneous/ConfiguringDbContext/ConfigureDbContextSample/ConfigureDbContextSample.csproj

Lines changed: 0 additions & 16 deletions
This file was deleted.

samples/core/Miscellaneous/ConfiguringDbContext/ConfiguringDbContext.csproj

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@
1010
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="8.0.0" />
1111
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="8.0.0" />
1212
<PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="8.0.0" />
13-
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.0" />
13+
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.0" />
14+
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="9.0.0" />
15+
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.0" />
16+
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.0" />
1417
</ItemGroup>
1518

1619
</Project>

0 commit comments

Comments
 (0)