使用C#EF6保存时,传递给系统调用的数据区域太小

使用C#EF6保存时,传递给系统调用的数据区域太小,c#,winforms,entity-framework,sql-server-ce,C#,Winforms,Entity Framework,Sql Server Ce,我有一个C#,Winforms EF6应用程序。数据库是SQL Server Compact 4。 在某些计算机(大多数工作正常)中,当保存下面代码中的简单对象时,我会遇到异常“传递给系统调用的数据区域太小” public void Add(SimpleObject simpleObject) { try { using (var db = new MyDbContext())

我有一个C#,Winforms EF6应用程序。数据库是SQL Server Compact 4。 在某些计算机(大多数工作正常)中,当保存下面代码中的简单对象时,我会遇到异常“传递给系统调用的数据区域太小”

        public void Add(SimpleObject simpleObject)
        {
            try
            {
                using (var db = new MyDbContext())
                {
                    db.SimpleObjects.AddOrUpdate(e => e.Description, simpleObject);
                    db.SaveChanges();
                }
            }
            catch(Exception ex)
            {
                _logger.ErrorException("Add", ex);
                throw;
            }
        }
SimpleObject非常简单,有两列([ID]INT NOT NULL IDENTITY(1,1),[DESCRIPTION]NVARCHAR(4000))。引发异常的实例在描述字段中有公共文本(少于150个字符),大多数计算机通常保存这些文本。命令AddOrUpdate引发异常

NLog记录的完整异常详细信息:

System.Data.Entity.Core.EntityCommandExecutionException:执行命令定义时出错。有关详细信息,请参见内部异常。-->System.Data.SqlServerCe.SqlCeException:传递给系统调用的数据区域太小。 位于System.Data.SqlServerCe.SqlCeCommand.ProcessResults(Int32小时) 在System.Data.SqlServerCe.SqlCeCommand.CompileQueryPlan()中 位于System.Data.SqlServerCe.SqlCeCommand.ExecuteCommand(命令行为、字符串方法、结果选项) 位于System.Data.Entity.SqlServerCompact.SqlCeMultiCommand.ExecuteReader(CommandBehavior) 在System.Data.Entity.Infrastructure.InternalDispatcher
1.Dispatch[TTarget,TInterceptionContext,TResult](TTarget,Func
3操作,TInterceptionContext拦截Context,Action
3执行,Action
3执行) 位于System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.Reader(DbCommand命令,DbCommandInterceptionContext interceptionContext) 位于System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition.ExecuteStorommands(EntityCommand EntityCommand,CommandBehavior) ---内部异常堆栈跟踪的结束--- 位于System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition.ExecuteStorommands(EntityCommand EntityCommand,CommandBehavior) 位于System.Data.Entity.Core.Objects.Internal.ObjectQueryExecutionPlan.Execute[TResultType](ObjectContext上下文,ObjectParameterCollection parameterValues) 在System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func
1 Func,IDbExecutionStrategy executionStrategy,Boolean startLocalTransaction,Boolean releaseConnectionOnSuccess)
在System.Data.Entity.Core.Objects.ObjectQuery中
位于System.Data.Entity.Core.Objects.ObjectQuery
1.GetResults(Nullable
1 forMergeOption) 在System.Data.Entity.Core.Objects.ObjectQuery
1.b_u0()中
在System.Data.Entity.Internal.LazyEnumerator中
在System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable
1源代码)处
在System.Data.Entity.Migrations.DbSetMigrationsExtensions.AddOrUpdate[TEntity](DbSet
1集,IEnumerable
1识别属性,InternalSet
1 InternalSet,TEntity[]实体) 在System.Data.Entity.Migrations.DbSetMigrationsExtensions.AddOrUpdate[TEntity](IDbSet
1集,表达式
1标识表达式,TEntity[]entities)>


任何帮助都将不胜感激

您应该升级到SQL CE 4.0 SP1,因为它包含该问题的修复程序-请参见

为什么要使用AddOrUpdate?某些AddOrUpdate故障导致异常?我将尝试并将其标记为answer(如果有效)。谢谢