Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/265.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/69.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# MySQL-Entity:列';iPrimaryKey';在表'中;表格详情';是DBNull吗_C#_Mysql_Entity Framework - Fatal编程技术网

C# MySQL-Entity:列';iPrimaryKey';在表'中;表格详情';是DBNull吗

C# MySQL-Entity:列';iPrimaryKey';在表'中;表格详情';是DBNull吗,c#,mysql,entity-framework,C#,Mysql,Entity Framework,我正在将Visual Studio 2013与Entity Framework 5和MySQL Server 5.7.9一起使用 尝试从数据库创建模型(或“从数据库更新模型”)时,将显示以下消息: 'System.Data.StrongTypingException:列的值 表“TableDetails”中的“IsPrimaryKey”为DBNull。-->System.InvalidCastException:指定的强制转换无效 我知道以前有人问过这个问题,但我没有找到任何解决办法。 此外,我

我正在将Visual Studio 2013与Entity Framework 5和MySQL Server 5.7.9一起使用

尝试从数据库创建模型(或“从数据库更新模型”)时,将显示以下消息:

'System.Data.StrongTypingException:列的值 表“TableDetails”中的“IsPrimaryKey”为DBNull。-->System.InvalidCastException:指定的强制转换无效

我知道以前有人问过这个问题,但我没有找到任何解决办法。 此外,我没有降级到MySQL 5.6的选项

即使对于一个简单的表,问题也会出现

样本表

CREATE TABLE new_table
(
  id int(11) NOT NULL AUTO_INCREMENT,
  name varchar(45) NOT NULL,
  PRIMARY KEY (id)
) 
ENGINE = InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
如果该表仅由主键组成,则将按原样创建模型

编辑: 如果我将这两个字段都设置为主键,则创建模型时不会出现任何错误

有人知道这件事吗

亲切的问候

完整错误堆栈:

由于以下异常,无法生成模型: '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和键列,列表
1和排除列,
列表
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 entitySetsForReadOnlyEntityTypes,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(字符串
storeModelNamespace,列出
1个错误) Microsoft.Data.Entity.Design.VisualStudio.ModelWizard.Engine.ModelBuilderEngine.GenerateModel(EdmxHelper 埃德姆谢尔珀。从数据库加载元数据花费了大量时间 00:00:00.5856317


从今天开始,这是一个经过验证的MySql社区服务器5.7.9错误,ID为

作为一种解决方法,我对应用程序进行了重新设计,首先使用代码练习

(ADO.NET实体数据对象->空代码优先模型)

并手动添加所有对象及其属性

使用的模块:

  • 实体框架6
  • MySql数据连接器6.8.9
  • MySQL VS Tools 1.2.5
  • 用于VS2013的EF6工具

    • 我们遇到了相同的错误。 但是,我认为这是MySQL的服务器问题

      地位:
      • EF5
      • MySQL VS Tools 1.2.5
      • VS社区2015
      • C#
      • 从数据库创建EF设计器(我使用的是日文版,所以菜单名是我的英文…)
      结果:
      • MySQL 5.7.9=>错误
      • MySQL 5.6.26=>没有错误
      解决方法 设置全局优化器_switch='派生_merge=off'

      这是一个已知的bug:

      在mysql控制台上运行命令:

      设置全局优化器\u switch='derived\u merge=off'

      设置@@optimizer\u switch='derived\u merge=OFF'

      (这个对我有用)

      使用以下命令验证更改是否有效:

      选择@@optimizer\u开关\G

      实体框架(版本6.1.3)和MySQL服务器(>=5.7.6)

      解决问题的一个办法是,

      1. Open Services (services.msc) and restart MySQL57 service.
      2. Execute the following commands in MySQL.
         use <<database name>>;
         set global optimizer_switch='derived_merge=OFF';
      3. Update the .edmx.
      
      1。打开服务(Services.msc)并重新启动MySQL57服务。
      2.在MySQL中执行以下命令。
      使用;
      设置全局优化器_switch='派生_merge=OFF';
      3.更新.edmx。
      
      这是迟来的答复。但希望它能帮助别人

      谢谢。

      就我而言:

      使用的模块:

      实体框架6 MySql数据连接器6.9.9 MySQL VS Tools 1.2.6 用于VS2015的EF6工具

      我必须这样做=>设置全局优化器_switch='derived'u merge=off';
      但是如果使用“root”用户登录,错误将继续。当使用“common”用户登录时,它会创建模型OK。

      我发现了一个很好的解决此类错误的方法

      1。解决方案(数据库优先) 与其尝试更新.edmx文件中的现有模型,不如在edmx中的一个实体上单击鼠标右键,然后选择->转到模型浏览器(项目地图管理器中会显示一个新的注册表)。 现在选择要更新的实体,右键单击并执行更新。在我的例子中,它每次都能工作,而不需要在mysql中关闭任何东西。但可能会发生这样的情况,即您将被迫手动更改某些关系。 如果此处出现任何错误(在我的情况下,非fk/pk键没有问题。如果您删除fk并尝试自行订购所有关系,您的db可能会被删除。但如果您只更新非主键/外键属性或只添加新表,则不会发生这种情况。

      use adventureworks; set global optimizer_switch='derived_merge=off'; set optimizer_switch='derived_merge=off'; select @@optimizer_switch; select @@GLOBAL.optimizer_switch;
use YourDB;
   set global optimizer_switch='derived_merge=OFF';
set global optimizer_switch='derived_merge=off';
set optimizer_switch='derived_merge=off';

select @@optimizer_switch;
select @@GLOBAL.optimizer_switch;