forked from PhenX/PhenX.EntityFrameworkCore.BulkInsert
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMySqlDialectBuilder.cs
More file actions
59 lines (44 loc) · 1.6 KB
/
MySqlDialectBuilder.cs
File metadata and controls
59 lines (44 loc) · 1.6 KB
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
using System.Text;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata;
using PhenX.EntityFrameworkCore.BulkInsert.Dialect;
using PhenX.EntityFrameworkCore.BulkInsert.Options;
namespace PhenX.EntityFrameworkCore.BulkInsert.MySql;
internal class MySqlServerDialectBuilder : SqlDialectBuilder
{
protected override string OpenDelimiter => "`";
protected override string CloseDelimiter => "`";
protected override bool SupportsMoveRows => false;
public override bool SupportsReturning => false;
protected override void AppendConflictCondition<T>(StringBuilder sql, OnConflictOptions<T> onConflictTyped)
{
throw new NotSupportedException("Conflict conditions are not supported in MYSQL");
}
protected override void AppendOnConflictUpdate(StringBuilder sql, IEnumerable<string> updates)
{
sql.AppendLine("UPDATE");
var i = 0;
foreach (var update in updates)
{
if (i > 0)
{
sql.Append(", ");
}
sql.Append(update);
i++;
}
}
protected override void AppendOnConflictStatement(StringBuilder sql)
{
sql.Append("ON DUPLICATE KEY");
}
protected override void AppendDoNothing(StringBuilder sql, IProperty[] insertedProperties)
{
var columnName = insertedProperties[0].GetColumnName();
sql.Append($"UPDATE {Quote(columnName)} = {GetExcludedColumnName(columnName)}");
}
protected override string GetExcludedColumnName(string columnName)
{
return $"VALUES({Quote(columnName)})";
}
}