本地 DB 抛出 Byte 数组截断到长度为 8000 的异常 [英] Local DB throws Byte array truncation to a length of 8000 exception

查看:30
本文介绍了本地 DB 抛出 Byte 数组截断到长度为 8000 的异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从 Map 控件中获取快照作为 WritableBitmap,将其转换为字节数组并将其保存在本地数据库中.它工作正常(我可以将字节数组转换回图像),直到我将更改提交到数据库.此时它会抛出异常字节数组截断到长度为 8000".我没有找到任何关于字节数组限制的文档.有谁知道如何增加8000的限制?我的字节数组是我模型的成员:

I'm trying to take a snapshot from a Map control as a WritableBitmap, convert it to a byte array and save it in the local DB. It works fine (I can convert the byte array back to the image) untill I submit the changes to the DB. At this point it throws an exception "Byte array truncation to a length of 8000". I didn't find any documentation about byte array limitation. Does anyone know how to increase the limit of 8000? My byte array is a member of my Model:

private byte[] _locationImage;
[Column]
public byte[] LocationImage
{
   get { return _locationImage; }
   set
   {
      if (_locationImage != value)
      {
         NotifyPropertyChanging("LocationImage");
         _locationImage = value;
         NotifyPropertyChanged("LocationImage");
      }
   }
}

推荐答案

如果您查看 SQL Compactdocs,你会看到一个 binary 或 varbinary 字段最多可以有 8000 个字节,所以这告诉我 byte[] 列被映射到 varbinary.要让它存储比这更大的数据,您需要让引擎使用 image 字段类型.这可能就像更新 Column 属性一样简单(未经测试):

If you look at the SQL Compact docs, you'll see that a binary or varbinary field can be at most 8000 bytes, so that tells me that a byte[] column gets mapped to varbinary. To get it to store data larger than that, you'd need to get the engine to use an image field type. This might be as simple as updating the Column attribute like this (untested):

[Column(DbType="image")]
public byte[] LocationImage { ... }

这篇关于本地 DB 抛出 Byte 数组截断到长度为 8000 的异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆