c# - 不允许将 nvarchar 数据类型隐式转换为 varbinary (max)。使用 CONVERT 函数执行此查询

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

遵循代码:

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) Allow nulls? true

ImageByte2 varbinary(MAX) Allow nulls? true

我在这里使用这个:http://entityframework-plus.net/

只有当我将 null 设置为 ImageByte2 时才会出现问题。以下错误:

The implicit conversion of the nvarchar data type into varbinary (max) is not allowed. Use the CONVERT function to perform this query

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

有什么解决办法吗?

最佳答案

该问题已通过最新版本得到纠正。

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

关于c# - 不允许将 nvarchar 数据类型隐式转换为 varbinary (max)。使用 CONVERT 函数执行此查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47232657/

相关文章:

c# - 有什么充分的理由不依赖业务逻辑中的数据库 key 完整性吗?

c# - 在不同的 DbContext 实例上重新执行 IQueryable?

oracle - 找不到与此版本兼容的 Entity Framework 数据库提供程序

mysql - 使用另一个表中的 avg() 进行更新?

mysql - SQL IF 逐日存在做增量更新否则插入数据

c# - 我可以使用 RabbitMQ .NET 客户端遍历队列吗?

c# - 无法在我的 WPF 应用程序中读取 True Type 字体文件!

c# - 如何在每个事件中只通知一个线程唤醒

c# - 'SQLite.SQLiteConnection' 的类型初始值设定项引发异常

mysql - cakePHP 更新表字段