Entity framework 实体框架6.1.3大型模型

Entity framework 实体框架6.1.3大型模型,entity-framework,Entity Framework,我使用的是实体框架6.1.3,当超出其限制时,我在添加/更新模型方面受到限制并低于错误。 由于以下异常,无法生成模型:“System.Data.Entity.Core.EntityCommandExecutionException:执行命令定义时出错。”。有关详细信息,请参见内部异常。-->System.Data.SqlClient.SqlException:传入请求的参数太多。服务器最多支持2100个参数。减少参数数量并重新发送请求。 位于System.Data.SqlClient.SqlCo

我使用的是实体框架6.1.3,当超出其限制时,我在添加/更新模型方面受到限制并低于错误。

由于以下异常,无法生成模型:“System.Data.Entity.Core.EntityCommandExecutionException:执行命令定义时出错。”。有关详细信息,请参见内部异常。-->System.Data.SqlClient.SqlException:传入请求的参数太多。服务器最多支持2100个参数。减少参数数量并重新发送请求。 位于System.Data.SqlClient.SqlConnection.OneError(SqlException异常、布尔断开连接、Action
1 wrapCloseInAction)
位于System.Data.SqlClient.SqlInternalConnection.OneError(SqlException异常、布尔断开连接、操作
1 wrapCloseInAction) 位于System.Data.SqlClient.TdsParser.ThroweException和Warning(TdsParserStateObject StateObjectStateObj、布尔调用方连接锁、布尔异步关闭) 位于System.Data.SqlClient.TdsParser.TryRun(RunBehavior RunBehavior、SqlCommand cmdHandler、SqlDataReader dataStream、BulkCopySimpleResultSet bulkCopyHandler、TdsParserStateObject stateObj、Boolean和dataReady) 位于System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()处 在System.Data.SqlClient.SqlDataReader.get_MetaData()处 位于System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds、RunBehavior、String ResetOptions String) 位于System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior、RunBehavior RunBehavior、Boolean returnStream、Boolean async、Int32超时、任务和任务、Boolean asyncWrite、SqlDataReader ds、Boolean describeParameterEncryptionRequest) 位于System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior、RunBehavior RunBehavior、Boolean returnStream、String方法、TaskCompletionSource
1 completion、Int32超时、任务和任务、Boolean asyncWrite)
位于System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior、RunBehavior RunBehavior、Boolean returnStream、String方法)
位于System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior,String方法)
位于System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior)
位于System.Data.Common.DbCommand.ExecuteReader(CommandBehavior)
在System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.b_uÈc(DbCommand t,DbCommandInterceptionContext
1c) 在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.Internal.InterceptableDbCommand.ExecuteDbDataReader(CommandBehavior) 位于System.Data.Common.DbCommand.ExecuteReader(CommandBehavior) 位于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.EntityClient.Internal.EntityCommandDefinition.Execute(EntityCommand EntityCommand,CommandBehavior) 位于System.Data.Entity.Core.EntityClient.EntityCommand.ExecuteReader(命令行为) 在Microsoft.Data.Entity.Design.VersioningFacade.ReverseeEngineerDB.SchemaDiscovery.EntityStoreSchemaAgeneratorDatabaseSchemaLoader.LoadDataTable[T](字符串sql,Func
2 orderByFunc,DataTable,EntityStoreSchemaFilterObject类型queryTypes,IEnumerable
1过滤器,字符串[]过滤器) 在Microsoft.Data.Entity.Design.VersioningFacade.ReverseeEngineerDB.SchemaDiscovery.EntityStoreSchemaAgenerator或DatabaseSchemaLoader.LoadRelationships(IEnumerable
1筛选器)
在Microsoft.Data.Entity.Design.VersioningFacade.ReverseeEngineerDB.SchemaDiscovery.EntityStoreSchemaAgent或DatabaseSchemaLoader.LoadStoreSchemaDetails(IList
1筛选器)中 位于Microsoft.Data.Entity.Design.VisualStudio.ModelWizard.Engine.ModelGenerator.GetStoreSchemaDetails(StoreSchemaConnectionFactory connectionFactory) 在Microsoft.Data.Entity.Design.VisualStudio.ModelWizard.Engine.ModelGenerator.CreateStoreModel()中 位于Microsoft.Data.Entity.Design.VisualStudio.ModelWizard.Engine.ModelGenerator.GenerateModel(列表
1错误)
位于Microsoft.Data.Entity.Design.VisualStudio.ModelWizard.Engine.ModelBuilderEngine.GenerateModels(String storeModelNamespace,ModelBuilderSettings设置,列表
1错误) 在Microsoft.Data.Entity.Design.VisualStudio.ModelWizard.Engine.ModelBuilderEngine.GenerateModel(ModelBuilderSettings设置、IVsUtils vsUtils、ModelBuilderEngineHostContext)中。 从数据库加载元数据花费了00:00:01.8445312。
生成模型需要00:00:15.0864187。

这不是实体框架限制,而是SQL server限制。IN语句的参数不能超过2100个

SELECT * FROM YourTable WHERE YourColumn IN (1,2,....,2101)
因此,我看到了两种解决方法:


  • 将查询拆分为多个查询,每次发送的时间都少于我遇到了相同的问题,我所做的是,从模型中删除所有实体,然后将它们添加回模型,然后就可以工作了。

    如果您要为DBFirst方法获取模型,我想您需要在EF上发布一个bug。同时,您可以从DBFirst更改为CodeFirst,从DB读取初始模型。感谢您的快速回复,我将在EF上发布我的错误。这有任何更新吗?问题解决了吗?我也有同样的问题。如何在特殊的DB表中插入所有参数并执行查询