本文介绍了实体框架-行大小大于允许的最大行大小8060的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个具有二进制数据类型的实体,并在SQL Server中具有相应的 varbinary(max)列。 EF会创建以下内容:

I have an entity with a binary datatype and a corresponding varbinary(max) column in SQL Server. EF creates this:

CREATE TABLE [dbo].[Attachments]
(
    [Id] INT IDENTITY(1,1) NOT NULL,
    [FileName] NVARCHAR(255) NOT NULL,
    [Attachment] VARBINARY(MAX) NOT NULL
);

当我尝试调用 .SaveChanges()从Entity Framework中,出现错误:

When I try to call .SaveChanges() from Entity Framework, I get an error:

我理解该错误,Google上有很多错误,但我不明白为什么要得到它。

I understand the error, there's plenty of that on Google but I don't understand why I'm getting it. Shouldn't this be managed by Entity Framework / SQL Server?

理查德

推荐答案

我看到该表定义出现此错误的唯一方法是,如果您以前有一个较大的固定宽度列,此列已被删除。

The only way I can see you getting this error with that table definition is if you have previously had a large fixed width column that has since been dropped.

CREATE TABLE [dbo].[Attachments] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [FileName] nvarchar(255) NOT NULL,
    [Attachment] varbinary(max) NOT NULL,
    Filler char(8000),
    Filler2 char(49)
);

ALTER TABLE  [dbo].[Attachments] DROP COLUMN Filler,Filler2

INSERT INTO [dbo].[Attachments]
([FileName],[Attachment])
VALUES
('Foo',0x010203)

哪个给予

如果是这种情况,请尝试重建表

If this is the case then try rebuilding the table

ALTER TABLE [dbo].[Attachments] REBUILD

这篇关于实体框架-行大小大于允许的最大行大小8060的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-25 11:45