.netcore 遇到的一些坑

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;

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值