mirror of
https://github.com/marcominerva/SqlDatabaseVectorSearch.git
synced 2026-08-04 09:48:57 +00:00
Flexible DbContext SQL provider selection and config
Replaced AddSqlServer with AddDbContext for ApplicationDbContext, enabling dynamic provider selection based on the connection string. Now uses UseAzureSql for Azure SQL targets and UseSqlServer with retry logic otherwise. Configured all queries to use NoTracking for improved performance.
This commit is contained in:
@@ -43,8 +43,22 @@ builder.Services.ConfigureHttpJsonOptions(options =>
|
|||||||
|
|
||||||
builder.Services.AddSingleton(TimeProvider.System);
|
builder.Services.AddSingleton(TimeProvider.System);
|
||||||
|
|
||||||
builder.Services.AddSqlServer<ApplicationDbContext>(builder.Configuration.GetConnectionString("SqlConnection"), optionsAction: options =>
|
builder.Services.AddDbContext<ApplicationDbContext>(options =>
|
||||||
{
|
{
|
||||||
|
var connectionString = builder.Configuration.GetConnectionString("SqlConnection")!;
|
||||||
|
|
||||||
|
if (connectionString.Contains("database.windows.net"))
|
||||||
|
{
|
||||||
|
options.UseAzureSql(connectionString);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
options.UseSqlServer(connectionString, sqlOptions =>
|
||||||
|
{
|
||||||
|
sqlOptions.EnableRetryOnFailure(maxRetryCount: 5, maxRetryDelay: TimeSpan.FromSeconds(10), errorNumbersToAdd: null);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
options.UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking);
|
options.UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user