实体框架6.1.3大型模型



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

由于以下异常,无法生成模型:"System.Data.Entity.Core.EntityCommandExecutionException:执行命令定义时出错。有关详细信息,请参阅内部异常。--->System.Data.SqlClient.SqlException:传入请求的参数太多。服务器最多支持2100个参数。减少参数数量并重新发送请求。位于System.Data.SqlClient.SqlConnection.OnError(SqlException异常,布尔breakConnection,操作1 wrapCloseInAction) at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action 1 wrapCloseInAction)位于System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj,布尔调用程序HasConnectionLock,布尔异步关闭)位于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 RunBehavior,String resetOptionsString)位于System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior,RunBehavior RunBehavior、Boolean returnStream、Boolean async、Int32超时、任务和任务、布尔asyncWrite、SqlDataReader ds、布尔describeParameterEncryptionRequest)位于System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior,RunBehavior RunBehavior、Boolean returnStream、String方法、TaskCompletionSource 1 completion, Int32 timeout, Task& task, Boolean asyncWrite) at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior) at System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior) at System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.<Reader>b__c(DbCommand t, DbCommandInterceptionContext 1 c)在System.Data.Entity.Infrastructure.Interception.InternalDispatcher 1.Dispatch[TTarget,TInterceptionContext,TResult](TTarget target, Func 3操作中,执行TInterceptionContext interceptionContext,操作3 executing, Action 3)位于System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.Reader(DbCommand命令,DbCommandInterceptionContext interceptionContext)位于System.Data.Entity.Interface.InterceptableDbCommand.ExecuteDbDataReader(CommandBehavior行为)位于System.Data.Common.DbCommand.ExecuteReader(CommandBehavior行为)位于System.Data.Entity.Core.EntityClient.Interface.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand EntityCommand,CommandBehavior behavior)---内部异常堆栈跟踪结束---位于System.Data.Entity.Core.EntityClient.Interface.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand EntityCommand,CommandBehavior behavior)位于System.Data.Entity.Core.EntityClient.Interface.EntityCommandDefinition.Execute(EntityCommand EntityCommand,CommandBehavior behavior)位于System.Data.Entity.Core.EntityClient.EntityCommand.ExecuteReader(CommandBehavior行为)位于Microsoft.Data.Entity.Design.VersingFacade.RiverseEngineerDb.SchemaDiscovery.EntityStoreSchemaGeneratorDatabaseSchemaLoader.LoadDataTable[T](字符串sql,函数2 orderByFunc, DataTable table, EntityStoreSchemaFilterObjectTypes queryTypes, IEnumerable 1筛选器,字符串[]筛选器别名)位于Microsoft.Data.Entity.Design.VersingFacade.RiverseEngineerDb.SchemaDiscovery.EntityStoreSchemaGeneratorDatabaseSchemaLoader.LoadRelationships(IEnumerable 1 filters) at Microsoft.Data.Entity.Design.VersioningFacade.ReverseEngineerDb.SchemaDiscovery.EntityStoreSchemaGeneratorDatabaseSchemaLoader.LoadStoreSchemaDetails(IList 1筛选器)位于Microsoft.Data.Entity.DesignMicrosoft.VisualStudio.ModelWizard.Engine.ModelGenerator.GetStoreSchemaDetails(StoreSchemaConnectionFactory connectionFactory)位于Microsoft.Data.Entity.DesignMicrosoft.VisualStudio.ModelWizard.Engine.ModelGenerator.CreateStoreModel()位于Microsoft.Data.Entity.DesignMicrosoft.VisualStudio.ModelWizard.Engine.ModelGenerator.GenerateModel(列出1 errors) at Microsoft.Data.Entity.Design.VisualStudio.ModelWizard.Engine.ModelBuilderEngine.GenerateModels(String storeModelNamespace, ModelBuilderSettings settings, List 1错误)位于Microsoft.Data.Entity.DesignMicrosoft.VisualStudio.ModelWizard.Engine.ModelBuilderEngine.GenerateModel(ModelBuilderSettings设置,IVsUtils vs.Utils,ModelBuilderEngineHostContext hostContext)'。从数据库加载元数据花费了00:00:018445312。生成模型需要00:00:15.0864187。

它不是实体框架限制,而是SQL服务器限制。IN语句的参数不能超过2100个。

SELECT * FROM YourTable WHERE YourColumn IN (1,2,....,2101)

所以我看到了两个解决办法:

  1. 将查询拆分为多个查询,每次发送少于<IN语句的2100个参数
  2. 在一个特殊的DB表中插入所有参数,然后对该表执行查询。例如,您可以创建一个临时表,插入超过2100个参数,然后用这个临时表联接您的表

CREATE TABLE #temptable (id int); INSERT INTO #temptable (id) VALUES (1), (2), (3) SELECT * FROM YourTable yt INNER JOIN #temptable tt ON yt.id = tt.id

我遇到了同样的问题,我所做的是,从模型中删除了所有实体,然后将它们添加回模型中,这就成功了。

最新更新