關注代碼:
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
和除null ImageByte1
ImageByte2
也會更新。
有解決方案嗎
使用最新版本已經糾正了該問題。
Nuget: https ://www.nuget.org/packages/Z.EntityFramework.Plus.EF6/