【.NET_EFCore中常见错误汇总】

记录一下在配置分层项目中所遇到的问题:

问题一:

        启动项目没有引用:Your startup project '8.1-MVC ' doesn't reference Microsoft.EntityFrameworkCore.Design. This package is required for the Entity Framework Core Tools to work. Ensure your startup project is correct, install the package, and try again.

 解决方法:将AdvantService该项目设置为启动项

问题二:

        Your target project '6.4-EFCore多层' doesn't match your migrations assembly '6.4-EFCoreBooks'. Either change your target project or change your migrations assembly. Change your migrations assembly by using DbContextOptionsBuilder. E.g. options.UseSqlServer(connection, b => b.MigrationsAssembly("6.4-EFCore多层")). By default, the migrations assembly is the assembly containing the DbContext. Change your target project to the migrations project by using the Package Manager Console's Default project drop-down list, or by executing "dotnet ef" from the directory containing the migrations project.  

 解决方法:注入EFCore时,设置包含基于代码的迁移的程序集

//注入EFCore
builder.Services.AddDbContextPool<DBContext>(opt => {
    string? conStr = builder.Configuration.GetSection("conStr").Value;
    opt.UseSqlServer(conStr, c => c.MigrationsAssembly("6.4-EFCore多层"));
});

  

问题三: 

        Your startup project '6.4-EFCore多层' doesn't reference Microsoft.EntityFrameworkCore.Design. This package is required for the Entity Framework Core Tools to work. Ensure your startup project is correct, install the package, and try again.

解决方法:引用Nuget包:Install-Package Microsoft.EntityFrameworkCore.Design -Version 7.0.0-preview.7.22376.2  

问题四:

        A connection was successfully established with the server, but then an error occurred during the login process. (provider: SSL Provider, error: 0 - 证书链是由不受信任的颁发机构颁发的。)  

问题五:

     Exception has bee  thrown by thetargetofaninvocation

     System.Reflection.TargetInvocationException:Exception has been thrown by the target of an invocation.-System.ArgumentNullException:Value cannot be null(Parameter'connectionString')atMicrosoft.EntityFrameworkCore.Utilities.Check.NotEmpty (Stringvalue,StringparameterName)at_6._4_EFCoreBooks.Migration.DBContextDesignFactory.

CreateDbContext(String[]args)in  

 解决办法:通常是由于数据库连接字符串有误引起的,检查连接字符串

问题六:

        A connection was successfully established with the server, but then an error occurred during the login process. (provider: SSL Provider, error: 0 - 证书链是由不受信任的颁发机构颁发的。)  

解决方法: 在数据库连接字符串后加Encrypt=False;

问题七:

        Add-Migration : 无法将“Add-Migration”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的拼写,如果包括路径,请确保路径正确,然后再试一次。

解决方法:项目安装Install-Package Microsoft.EntityFrameworkCore.Tools -Version 7.0.0-preview.7.22376.2

 

以上是我在配置EFCore时出现的问题,希望能给大家提供帮助。

  • 8
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值