当前位置:   article > 正文

.netcore 遇到的一些坑_invalidoperationexception: an exception has been r

invalidoperationexception: an exception has been raised that is likely due t

1、联合主键异常:

InvalidOperationException: Entity type '***' has composite primary key defined with data annotations. To set composite primary key, use fluent API.

解决方案:EFCore 联合主键不支持注解的方式,需要使用fluent API。

即,要把这种注解的方式

  1. public class OtaVersion
  2. {
  3. [Key, Column(Order = 0)]
  4. public int ProductClass { get; set; }
  5. [Key, Column(Order = 1)]
  6. public int ProductSku { get; set; }
  7. public int SourceType { get; set; }
  8. }

更换为fluent API:

  1. protected override void OnModelCreating(ModelBuilder modelBuilder)
  2. {
  3. modelBuilder.Entity<OtaVersion>().HasKey(t => new { t.ProductClass, t.ProductSku });
  4. }

 

2、

An exception has been raised that is likely due to a transient failure. Consider enabling transient error resiliency by adding 'EnableRetryOnFailure()' to the 'UseMySql' call.

解决方案:这一般是连接方面的问题,确认一下连接字符串是否正确,注意port,sslMode等的设置(不区分大小写)

Server=127.0.0.1;Port=3306;Database=数据库;User ID=账户;Password=密码;Persistsecurityinfo=True;Character Set=utf8;Allow User Variables=True;SslMode=None;

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/神奇cpp/article/detail/891841
推荐阅读
相关标签
  

闽ICP备14008679号