-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathTesDbContext.cs
44 lines (38 loc) · 1.31 KB
/
TesDbContext.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using System;
using Microsoft.EntityFrameworkCore;
using Tes.Models;
namespace Tes.Repository
{
public class TesDbContext : DbContext
{
public const string TesTasksPostgresTableName = "testasks";
public TesDbContext()
{
// Default constructor, which is required to run the EF migrations tool,
// "dotnet ef migrations add InitialCreate"
}
public TesDbContext(string connectionString)
{
ArgumentException.ThrowIfNullOrEmpty(connectionString, nameof(connectionString));
ConnectionString = connectionString;
}
public string ConnectionString { get; set; }
public DbSet<TesTaskDatabaseItem> TesTasks { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if (!optionsBuilder.IsConfigured)
{
// use PostgreSQL
optionsBuilder
.UseNpgsql(ConnectionString, options =>
{
options.EnableRetryOnFailure();
options.MaxBatchSize(1000);
})
.UseLowerCaseNamingConvention();
}
}
}
}