Sam*_*era 5 blob sql-server-ce dapper
当使用超过 8000 字节数据的 BLOB 时,您需要专门设置Parameter.SqlDbType = SqlDbType.Image才能使其工作(如此处所述)。
Dapper,当它看到一个byte[]字段时,默认为 a SqlDbType.Binary,这意味着对于较大的 blob,插入和更新将失败并出现数据截断错误。
这个问题有优雅的解决方案吗?我能看到的唯一选择是使用 ADO.NET 方法对整个事务进行编码。
我有同样的问题。解决如下:
private static IDbCommand SetupCommand(IDbConnection cnn, IDbTransaction transaction,
string sql, Action<IDbCommand, object> paramReader,
object obj, int? commandTimeout,
CommandType? commandType)
{
var cmd = cnn.CreateCommand();
var bindByName = GetBindByName(cmd.GetType());
if (bindByName != null) bindByName(cmd, true);
if (transaction != null)
cmd.Transaction = transaction;
cmd.CommandText = sql;
if (commandTimeout.HasValue)
cmd.CommandTimeout = commandTimeout.Value;
if (commandType.HasValue)
cmd.CommandType = commandType.Value;
if (paramReader != null)
{
paramReader(cmd, obj);
}
//CODTEC SISTEMAS
foreach (System.Data.SqlServerCe.SqlCeParameter item in cmd.Parameters)
{
if (item.SqlDbType == System.Data.SqlDbType.VarBinary)
item.SqlDbType = System.Data.SqlDbType.Image;
}
//CODTEC SISTEMAS
return cmd;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5637 次 |
| 最近记录: |