【问题标题】:The implicit conversion of the nvarchar data type into varbinary (max) is not allowed. Use the CONVERT function to perform this query不允许将 nvarchar 数据类型隐式转换为 varbinary (max)。使用 CONVERT 函数执行此查询
【发布时间】: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 函数执行此查询

现在我将ImageByte1ImageByte2 定义为null,它会正常更新,或者ImageByte1ImageByte2 除了null 也会更新。

有什么办法吗?

【问题讨论】:

  • 哦,你考虑过一个空字节数组而不是一个空数组吗?
  • @ErikE ,是的,我希望它为空
  • @ErikE,已编辑后
  • 显示你的表定义。
  • @JanMuncinsky,已编辑后

标签: c# entity-framework sql-update entity-framework-plus


【解决方案1】:

这个问题已经用最新的版本修正了。

Nuget:https://www.nuget.org/packages/Z.EntityFramework.Plus.EF6/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-06-07
    • 1970-01-01
    • 2018-04-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多