【发布时间】:2017-11-29 21:08:21
【问题描述】:
关注代码:
byte[] image1 = ConvertTo.Bytes(Request.Files[0]);
byte[] image2 = null;
ctx
.Users
.Where(x => x.Id == 1)
.Update(x => new User()
{
ImageByte1 = image1,
ImageByte2 = image2
});
表定义:
ImageByte1 varbinary(MAX) 允许空值吗?真的
ImageByte2 varbinary(MAX) 允许空值吗?真的
我在这里使用这个:http://entityframework-plus.net/
只有当我将 null 设置为 ImageByte2 时才会出现问题。以下错误:
nvarchar 数据类型到 varbinary (max) 的隐式转换 不被允许。使用 CONVERT 函数执行此查询
现在我将ImageByte1 和ImageByte2 定义为null,它会正常更新,或者ImageByte1 和ImageByte2 除了null 也会更新。
有什么办法吗?
【问题讨论】:
-
哦,你考虑过一个空字节数组而不是一个空数组吗?
-
@ErikE ,是的,我希望它为空
-
@ErikE,已编辑后
-
显示你的表定义。
-
@JanMuncinsky,已编辑后
标签: c# entity-framework sql-update entity-framework-plus