tgstation-server 5.12.7
The /tg/station 13 server suite
Loading...
Searching...
No Matches
SqlServerDatabaseContext.cs
Go to the documentation of this file.
1using System;
2using System.Data.SqlClient;
3
4using Microsoft.EntityFrameworkCore;
5
7
9{
14 {
19 public SqlServerDatabaseContext(DbContextOptions<SqlServerDatabaseContext> dbContextOptions) : base(dbContextOptions)
20 {
21 }
22
28 public static void ConfigureWith(DbContextOptionsBuilder options, DatabaseConfiguration databaseConfiguration)
29 {
30 ArgumentNullException.ThrowIfNull(options);
31 ArgumentNullException.ThrowIfNull(databaseConfiguration);
32
33 if (databaseConfiguration.DatabaseType != DatabaseType.SqlServer)
34 throw new InvalidOperationException($"Invalid DatabaseType for {nameof(SqlServerDatabaseContext)}!");
35
36#if NET7_0_OR_GREATER
37#error Perform this breaking config change
38#endif
39
40 // Workaround for breaking change https://learn.microsoft.com/en-us/ef/core/what-is-new/ef-core-7.0/breaking-changes#encrypt-true
41 var connectionString = databaseConfiguration.ConnectionString;
42 if (!connectionString.Contains("Encrypt=", StringComparison.OrdinalIgnoreCase))
43 {
44 var connectionStringBuilder = new SqlConnectionStringBuilder(databaseConfiguration.ConnectionString)
45 {
46 Encrypt = false,
47 };
48
49 connectionString = connectionStringBuilder.ToString();
50 }
51
52 options.UseSqlServer(
53 connectionString,
54 sqlServerOptions =>
55 {
56 sqlServerOptions.EnableRetryOnFailure();
57 sqlServerOptions.UseQuerySplittingBehavior(QuerySplittingBehavior.SingleQuery);
58 });
59 }
60 }
61}
Configuration options for the Database.DatabaseContext.
string ConnectionString
The connection string for the database.
DatabaseType DatabaseType
The Configuration.DatabaseType to create.
Backend abstract implementation of IDatabaseContext.
SqlServerDatabaseContext(DbContextOptions< SqlServerDatabaseContext > dbContextOptions)
Initializes a new instance of the SqlServerDatabaseContext class.
static void ConfigureWith(DbContextOptionsBuilder options, DatabaseConfiguration databaseConfiguration)
Configure the SqlServerDatabaseContext.
DatabaseType
Type of database to user.
Definition: DatabaseType.cs:7