-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
MysqlContext.cs
73 lines (63 loc) · 2.89 KB
/
MysqlContext.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
63
64
65
66
67
68
69
70
71
72
73
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using WorkflowCore.Persistence.EntityFramework.Models;
using WorkflowCore.Persistence.EntityFramework.Services;
namespace WorkflowCore.Persistence.MySQL
{
public class MysqlContext : WorkflowDbContext
{
private readonly string _connectionString;
private readonly Action<MySqlDbContextOptionsBuilder> _mysqlOptionsAction;
public MysqlContext(string connectionString, Action<MySqlDbContextOptionsBuilder> mysqlOptionsAction = null)
{
_connectionString = connectionString;
_mysqlOptionsAction = mysqlOptionsAction;
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
base.OnConfiguring(optionsBuilder);
#if NETSTANDARD2_0
optionsBuilder.UseMySql(_connectionString, _mysqlOptionsAction);
#elif NETSTANDARD2_1_OR_GREATER || NET6_0_OR_GREATER
optionsBuilder.UseMySql(_connectionString, ServerVersion.AutoDetect(_connectionString), _mysqlOptionsAction);
#endif
}
protected override void ConfigureSubscriptionStorage(EntityTypeBuilder<PersistedSubscription> builder)
{
builder.ToTable("Subscription");
builder.Property(x => x.PersistenceId).ValueGeneratedOnAdd();
}
protected override void ConfigureWorkflowStorage(EntityTypeBuilder<PersistedWorkflow> builder)
{
builder.ToTable("Workflow");
builder.Property(x => x.PersistenceId).ValueGeneratedOnAdd();
}
protected override void ConfigureExecutionPointerStorage(EntityTypeBuilder<PersistedExecutionPointer> builder)
{
builder.ToTable("ExecutionPointer");
builder.Property(x => x.PersistenceId).ValueGeneratedOnAdd();
}
protected override void ConfigureExecutionErrorStorage(EntityTypeBuilder<PersistedExecutionError> builder)
{
builder.ToTable("ExecutionError");
builder.Property(x => x.PersistenceId).ValueGeneratedOnAdd();
}
protected override void ConfigureExetensionAttributeStorage(EntityTypeBuilder<PersistedExtensionAttribute> builder)
{
builder.ToTable("ExtensionAttribute");
builder.Property(x => x.PersistenceId).ValueGeneratedOnAdd();
}
protected override void ConfigureEventStorage(EntityTypeBuilder<PersistedEvent> builder)
{
builder.ToTable("Event");
builder.Property(x => x.PersistenceId).ValueGeneratedOnAdd();
}
protected override void ConfigureScheduledCommandStorage(EntityTypeBuilder<PersistedScheduledCommand> builder)
{
builder.ToTable("ScheduledCommand");
builder.Property(x => x.PersistenceId).ValueGeneratedOnAdd();
}
}
}