1、联合主键异常:
InvalidOperationException: Entity type '***' has composite primary key defined with data annotations. To set composite primary key, use fluent API.
解决方案:EFCore 联合主键不支持注解的方式,需要使用fluent API。
即,要把这种注解的方式
public class OtaVersion
{
[Key, Column(Order = 0)]
public int ProductClass { get; set; }
[Key, Column(Order = 1)]
public int ProductSku { get; set; }
public int SourceType { get; set; }
}
更换为fluent API:
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<OtaVersion>().HasKey(t => new { t.ProductClass, t.ProductSku });
}
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;