gpt4 book ai didi

c# - EF4 将 varbinary(max) 映射到二进制 - 代码优先错误

转载 作者:可可西里 更新时间:2023-11-01 08:37:50 26 4
gpt4 key购买 nike

我有一个名为 Attachment 的 POCO 类,它映射到 SqlServer 中的一个表,其中有一个 VarBinary(max) 字段。该字段包含文件。

POCO类看起来像这样

public class Attachment
{
public string AttachmentId { get; set; }
public string AttachmentTypeId { get; set; }
public string Title { get; set; }
public string Text { get; set; }
public Binary Data { get; set; }
}

映射看起来像这样

modelBuilder.Entity<Attachment>().Property(a => a.Data).HasColumnName("col_data");

但是映射会抛出错误

The type 'System.Date.Linq.Binary' must be a non-nullable value type in order to use it as a parameter 'T'

如果我使用字节数组,映射工作正常,但这似乎在通过的过程中破坏了数据。

数据库中的文件有一个初始二进制字符串,如:-

0x504B0304140008000800027923400000000000000000000000001F000000

我认为这是一个 JPG 文件。任何帮助将文件从数据库中取出的任何帮助将不胜感激。

最佳答案

Binary 数据类型仅适用于 Linq-to-Sql。 EF 无法使用它。 EF 的正确数据类型是字节数组 (byte[])。

关于c# - EF4 将 varbinary(max) 映射到二进制 - 代码优先错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8757460/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com