Tom*_*les 11 c# sql-server entity-framework entity-framework-4
我有一个POCO类,它被Attachment映射到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; }
}
Run Code Online (Sandbox Code Playgroud)
映射看起来像这样
modelBuilder.Entity<Attachment>().Property(a => a.Data).HasColumnName("col_data");
Run Code Online (Sandbox Code Playgroud)
但是映射会引发错误
The type 'System.Date.Linq.Binary' must be a non-nullable value type in order to use it as a parameter 'T'
Run Code Online (Sandbox Code Playgroud)
如果我使用字节数组,映射工作正常,但这似乎在破坏通过的数据.
数据库中的文件有一个初始二进制字符串,如: -
0x504B0304140008000800027923400000000000000000000000001F000000
Run Code Online (Sandbox Code Playgroud)
我认为这是一个JPG文件.任何帮助将文件从数据库中取出的任何帮助都将受到赞赏.