记录一下在配置分层项目中所遇到的问题:
问题一:
启动项目没有引用: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文章来源:https://www.toymoban.com/news/detail-459115.html
文章来源地址https://www.toymoban.com/news/detail-459115.html
以上是我在配置EFCore时出现的问题,希望能给大家提供帮助。
到了这里,关于【.NET_EFCore中常见错误汇总】的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!