【发布时间】:2016-01-15 02:55:33
【问题描述】:
我在 .NET 中有一个 Web 服务。有了这个 ws,我可以接收 Base64 中的图像,我通过实体框架将它存储到我的数据库中。为此,我将此字符串转换为字节。使用此代码:
static byte[] GetBytes(string str)
{
byte[] bytes = new byte[str.Length * sizeof(char)];
System.Buffer.BlockCopy(str.ToCharArray(), 0, bytes, 0, bytes.Length);
return bytes;
}
现在,我必须从数据库中获取这些数据并从 ws 中显示出来。所以我有这段代码来检索数据并打印响应:
private IQueryable<ImmaginiSecSocDTO> getSecSocData(int? id)
{
if (id != null)
{
return from u in db_data.CAMERA_SEC_SOC
where u.ID == id
select new ImmaginiSecSocDTO()
{
image = System.Text.Encoding.UTF8.GetString(u.Image),
image_width = u.image_width,
image_height= u.image_height,
type = u.type,
rectangle = new ImmaginiSecSocDTO.Rectangle()
{
rects = from pi in db_data.CAMERA_SEC_SOC_Rectangles
where pi.ID_SecSoc == id
select new ImmaginiSecSocDTO.Rectangle.Rect()
{
height= pi.height,
width = pi.width,
x = pi.x,
y=pi.y
}
}
};
}
return null;
}
但如果我尝试运行它,我会收到以下错误消息:
"ExceptionType": "System.NotSupportedException", "StackTrace": " 在 System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.DefaultTranslator.Translate(ExpressionConverter parent, MethodCallExpression call)\r\n 在 System.Data.Entity.Core.Objects.ELinq.ExpressionConverter .MethodCallTranslator.TypedTranslate(ExpressionConverter parent, MethodCallExpression linq)\r\n in System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TypedTranslator`1.Translate(ExpressionConverter parent, Expression linq)\r\n in System.Data .Entity.Core.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq)\r\n
【问题讨论】:
标签: sql entity-framework byte