-
Notifications
You must be signed in to change notification settings - Fork 177
/
TranscriptContext.cs
56 lines (48 loc) · 1.72 KB
/
TranscriptContext.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
using System;
using Microsoft.EntityFrameworkCore;
namespace Bot.Builder.Community.Storage.EntityFramework
{
/// <summary>
/// DbContext for TranscriptEntitys
/// </summary>
public class TranscriptContext : DbContext
{
private string _connectionString;
/// <summary>
/// Constructor for TranscriptContext receiving connectionString
/// </summary>
/// <param name="connectionString">Connection string to use when configuring the options during <see cref="OnConfiguring"/></param>
public TranscriptContext(string connectionString)
: base()
{
if (string.IsNullOrEmpty(connectionString))
{
throw new ArgumentNullException(nameof(connectionString));
}
_connectionString = connectionString;
}
/// <summary>
/// TranscriptEntity records
/// </summary>
public virtual DbSet<TranscriptEntity> Transcript { 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<TranscriptEntity>(entity =>
{
entity.ToTable(nameof(TranscriptEntity));
entity.HasIndex(e => e.Conversation);
entity.HasIndex(e => e.Channel);
entity.HasIndex(e => new { e.Channel, e.Conversation });
entity.HasKey(e => e.Id);
});
}
}
}