使用 Dapper 保存旨在进入 AlwaysEncrypted 货币字段的十进制数据会导致此错误:
操作数类型冲突:用 (...) 加密的小数 (5,1) 与用 (...) 加密的钱不兼容
您如何明确告诉 Dapper 使用 money 作为 C# Decimal <-> Money 作为首选映射的类型?
decimal income = 4500m;
using (var connection = new ReliableSqlConnection(connectionString)) {
try {
connection.Open();
connection.Query<int>(
@"INSERT INTO [tablename]
([MonthlyAfterTaxIncome])
VALUES
(@MonthlyAfterTaxIncome);
SELECT CAST(SCOPE_IDENTITY() as int)",
new {
MonthlyAfterTaxIncome = income
})
.FirstOrDefault();
} finally {
connection.Close();
}
}
栏目详情:
[MonthlyAfterTaxIncome] [money] ENCRYPTED WITH (COLUMN_ENCRYPTION_KEY = [KeyName], ENCRYPTION_TYPE = Deterministic, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256') NOT NULL,)