Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# VS Error:列';iPrimaryKey';在表'中;表格详情';是DBNull吗_C#_Mysql_Entity Framework_Visual Studio_Phpmyadmin - Fatal编程技术网

C# VS Error:列';iPrimaryKey';在表'中;表格详情';是DBNull吗

C# VS Error:列';iPrimaryKey';在表'中;表格详情';是DBNull吗,c#,mysql,entity-framework,visual-studio,phpmyadmin,C#,Mysql,Entity Framework,Visual Studio,Phpmyadmin,我正在使用Visual Studio 2015和Entity Framework 6以及MySQL Server 5.7.13 mysql服务器来自web和mysql服务器托管服务,我使用phpmyadmin访问它 当我尝试从数据库更新/生成模型时,出现以下错误(服务器连接成功) 由于以下异常,无法生成模型:“System.Data.StrongTypingException:表“TableDetails”中“IsPrimaryKey”列的值为DBNull。-->System.InvalidCa

我正在使用Visual Studio 2015和Entity Framework 6以及MySQL Server 5.7.13 mysql服务器来自web和mysql服务器托管服务,我使用phpmyadmin访问它

当我尝试从数据库更新/生成模型时,出现以下错误(服务器连接成功)

由于以下异常,无法生成模型:“System.Data.StrongTypingException:表“TableDetails”中“IsPrimaryKey”列的值为DBNull。-->System.InvalidCastException:指定的强制转换无效。 在Microsoft.Data.Entity.Design.VersioningFacade.ReverseeEngineerDB.SchemaDiscovery.TableDetailsRow.get_IsPrimaryKey()中 ---内部异常堆栈跟踪的结束--- 在Microsoft.Data.Entity.Design.VersioningFacade.ReverseeEngineerDB.SchemaDiscovery.TableDetailsRow.get_IsPrimaryKey()中 位于Microsoft.Data.Entity.Design.VersioningFacade.ReverseeEngineerDB.StoreModelBuilder.CreateProperties(IList`1列,IList`1错误,列表`1和keyColumns,列表`1和excludedColumns,列表`1和invalidKeyTypeColumns) 位于Microsoft.Data.Entity.Design.VersioningFacade.ReverseeEngineerDB.StoreModelBuilder.CreateEntityType(IList`1列,布尔值&需要定义查询) 在Microsoft.Data.Entity.Design.VersioningFacade.ReverseeEngineerDB.StoreModelBuilder.CreateEntitySets(IEnumerable`1 tableDetailsRows、EntityRegister EntityRegister、IList`1 EntitySets for ReadOnlyEntityTypes、DbObjectType objectType) 在Microsoft.Data.Entity.Design.VersioningFacade.ReverseeEngineerDB.StoreModelBuilder.CreateEntitySets(IEnumerable`1 tableDetailsRowsForTables,IEnumerable`1 tableDetailsRowsForViews,EntityRegister EntityRegister) 位于Microsoft.Data.Entity.Design.VersioningFacade.ReverseeEngineerDB.StoreModelBuilder.Build(StoreSchemaDetails StoreSchemaDetails) 在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:00.6311313。 生成模型花费了00:00:01.9805600。 这个问题已经被问了好几次,并且得到了回答,大多数人都认为这两种解决方案都可以解决这个问题:
-降级到MySQL 5.6
-设置全局优化器\u switch='derived\u merge=OFF'(需要超级权限)
-设置@@optimizer\u switch='derived\u merge=OFF'

我(通过我的phpmyadmin工具)与支持人员交谈,并请他们帮助我解决上述任一解决方案,他们的回答如下:

The MySQL version on all servers was very recently upgraded to MySQL 5.7. Indeed, super user privileges are not available for your MySQL users. Also, it is not technically possible to revert the MySQL version back to 5.6. 所有服务器上的MySQL版本最近都升级到了MySQL 5.7。 事实上,超级用户权限不适用于MySQL用户。 而且,从技术上讲,将MySQL版本恢复到5.6是不可能的。 我进一步问他们为什么这些解决方案不可能,因为这些是我问题的唯一已知解决方案,这是他们的最终回答:

Please note that your account is hosted on a shared hosting server, and there are lots of other users whose accounts are located on the same server where your account is hosted, hence we cannot globally turn off that feature, as this would affect negatively the performance of the database server for all the hosting accounts on the server (including your account as well). 请注意,您的帐户托管在共享托管服务器上, 还有许多其他用户的帐户位于同一台服务器上 您的帐户所在地,因此我们无法在全球范围内关闭该功能, 因为这将对数据库服务器的性能产生负面影响 服务器上的所有托管帐户(也包括您的帐户)。
因此,我向社区提出的最后一个问题是:这里的任何人都知道除了上面列出的解决方案以外的任何解决方案(具体针对我的情况和限制)

因为我无法及时找到有效的解决方案,而且我的问题很紧急,所以我必须找到解决办法

我使用了一个不同的mysql服务器托管平台,并在那里迁移了我的数据库。它使用的是MariaDB,因此mysql版本更低(5.6)


最后,我使用Visual Studio data connection正常连接到新的数据库,它成功了。

我遇到了同样的问题,并使用以下答案解决了问题:

在MySQL中

use <<database name>>;
set global optimizer_switch='derived_merge=off';
set optimizer_switch='derived_merge=off';
使用;
设置全局优化器_switch='派生_merge=off';
设置优化器_switch='派生_merge=off';
use <<database name>>;
set global optimizer_switch='derived_merge=off';
set optimizer_switch='derived_merge=off';