-
Notifications
You must be signed in to change notification settings - Fork 177
/
BotDataContext.cs
62 lines (53 loc) · 1.87 KB
/
BotDataContext.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
using System;
using Microsoft.EntityFrameworkCore;
namespace Bot.Builder.Community.Storage.EntityFramework
{
/// <summary>
/// DbContext for BotDataEntitys
/// </summary>
public class BotDataContext : DbContext
{
private string _connectionString;
/// <summary>
/// Constructor for BotDataContext receiving connectionString
/// </summary>
/// <param name="connectionString">Connection string to use when configuring the options during <see cref="OnConfiguring"/></param>
public BotDataContext(string connectionString)
: base()
{
if (string.IsNullOrEmpty(connectionString))
{
throw new ArgumentNullException(nameof(connectionString));
}
_connectionString = connectionString;
}
/// <summary>
/// Constructor for BotDataContext receiving DBContextOptions
/// </summary>
/// <param name="options">Options to use for configuration.</param>
public BotDataContext(DbContextOptions<BotDataContext> options)
: base(options)
{ }
/// <summary>
/// BotDataEntity records
/// </summary>
public virtual DbSet<BotDataEntity> BotDataEntity { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if (!optionsBuilder.IsConfigured)
{
optionsBuilder.UseSqlServer(_connectionString);
}
base.OnConfiguring(optionsBuilder);
}
protected override void OnModelCreating(ModelBuilder builder)
{
builder.Entity<BotDataEntity>(entity =>
{
entity.ToTable(nameof(BotDataEntity));
entity.HasIndex(e => e.RealId);
entity.HasKey(e => e.Id);
});
}
}
}