2012-03-09 2 views
2

8000 바이트 이상의 데이터가있는 BLOB를 사용하려면 Parameter.SqlDbType = SqlDbType.Image을 설정하여 작동되게하십시오 (as explained here).BLOB 및 SQL Server CE에서 Dapper 사용

Dapper의 경우 byte[] 필드가 표시되며 기본값은 SqlDbType.Binary입니다. 즉, 더 큰 blob의 경우 데이터 잘림 오류로 인해 삽입 및 업데이트가 실패합니다.

이 문제에 대한 우아한 해결책이 있습니까? 내가 볼 수있는 유일한 옵션은 ADO.NET 메서드로 전체 트랜잭션을 코딩하는 것입니다.

+0

당신이 말끔 소스를 살펴 경우 (http://code.google.com/p/dapper-dot-net/source/browse/Dapper/SqlMapper.cs) 당신이 할 수 적절한 SqlDbType을 반환하는 "LookupDbType"함수에 특별한 경우를 추가하십시오. 그래도 뭔가 다른 것이 단절되면 단서가 없습니다. – Alex

+0

감사! 정적 SqlMapper 생성자를 수정하고 다음 줄을 수정합니다 : typeMap [typeof (byte [])] = DbType.Binary; – Sameera

+2

오, 그건 고통입니다. 나는 당신이 더 나은 것에 대한 버그로 더 잘 로깅 할 수 있다고 생각합니다. –

답변

0

나는 동일한 문제가있었습니다. 해결 다음과 같이

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; 
    } 
관련 문제