实体框架6.1.3大型模型

时间:2016-04-07 06:36:22

标签: entity-framework

我正在使用实体框架6.1.3,当超出其限制时,我在添加/更新模型时遇到限制 并获得以下错误

由于以下异常,无法生成模型:&#39; System.Data.Entity.Core.EntityCommandExecutionException:执行命令定义时发生错误。有关详细信息,请参阅内部异常---&GT; System.Data.SqlClient.SqlException:传入的请求包含太多参数。服务器最多支持2100个参数。减少参数数量并重新发送请求。    在System.Data.SqlClient.SqlConnection.OnError(SqlException异常,Boolean breakConnection,Action 1 wrapCloseInAction) at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action 1 wrapCloseInAction)    在System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj,Boolean callerHasConnectionLock,Boolean asyncClose)    在System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior,SqlCommand cmdHandler,SqlDataReader dataStream,BulkCopySimpleResultSet bulkCopyHandler,TdsParserStateObject stateObj,Boolean&amp; 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 timeout,Task&amp; task,Boolean asyncWrite,SqlDataReader ds,Boolean describeParameterEncryptionRequest)    在System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior,RunBehavior runBehavior,Boolean returnStream,String method,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,Action 3 executing, Action 3执行)    在System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.Reader(DbCommand命令,DbCommandInterceptionContext interceptionContext)    在System.Data.Entity.Internal.InterceptableDbCommand.ExecuteDbDataReader(CommandBehavior behavior)    在System.Data.Common.DbCommand.ExecuteReader(CommandBehavior行为)    在System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand,CommandBehavior behavior)    ---内部异常堆栈跟踪结束---    在System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand,CommandBehavior behavior)    在System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition.Execute(EntityCommand entityCommand,CommandBehavior behavior)    在System.Data.Entity.Core.EntityClient.EntityCommand.ExecuteReader(CommandBehavior行为)    at Microsoft.Data.Entity.Design.VersioningFacade.ReverseEngineerDb.SchemaDiscovery.EntityStoreSchemaGeneratorDatabaseSchemaLoader.LoadDataTable [T](String sql,Func 2 orderByFunc, DataTable table, EntityStoreSchemaFilterObjectTypes queryTypes, IEnumerable 1 filters,String [] filterAliases)    在Microsoft.Data.Entity.Design.VersioningFacade.ReverseEngineerDb.SchemaDiscovery.EntityStoreSchemaGeneratorDatabaseSchemaLoader.LoadRelationships(IEnumerable 1 filters) at Microsoft.Data.Entity.Design.VersioningFacade.ReverseEngineerDb.SchemaDiscovery.EntityStoreSchemaGeneratorDatabaseSchemaLoader.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 errors) at Microsoft.Data.Entity.Design.VisualStudio.ModelWizard.Engine.ModelBuilderEngine.GenerateModels(String storeModelNamespace, ModelBuilderSettings settings, List 1个错误)    在Microsoft.Data.Entity.Design.VisualStudio.ModelWizard.Engine.ModelBuilderEngine.GenerateModel(ModelBuilderSettings设置,IVsUtils vsUtils,ModelBuilderEngineHostContext hostContext)&#39;。 从数据库加载元数据时间为00:00:01.8445312。 生成模型需要00:00:15.0864187。

2 个答案:

答案 0 :(得分:0)

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

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

所以我看到了2个解决方法:

  1. 在几个查询中拆分查询,每次发送少于IN语句的&lt; 2100参数。
  2. 将所有参数插入特殊数据库表中,然后针对该表执行查询。 例如,您可以创建一个临时表,插入超过2100个参数,然后使用此临时表加入表。
  3. 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

答案 1 :(得分:0)

我遇到了同样的问题,我做的是,删除了模型中的所有实体,然后将它们添加回模型并且它已经工作了。