以项目名MpaAbp为例
Your target project ‘MpaAbp.Core’ doesn’t reference EntityFramework. This package is required for the Entity Framework Core Tools to work. Ensure your target project is correct, install the package, and try again.
默认项目选择为Migrator
No migrations configuration type was found in the assembly ‘MpaAbp.Migrator’. (In Visual Studio you can use the Enable-Migrations command from Package Manager Console to add a migrations configuration).
默认项目选择为EntityFramework 控制台执行命令 Enable-Migrations -ContextTypeName “MpaAbp.MpaAbpDbContext” -ProjectName “MpaAbp.EntityFramework” -StartUpProjectName “MpaAbp.Web” -ConnectionStringName “default” -Verbose
如果报下面的错
The context type ‘MpaAbp.MpaAbpDbContext’ was not found in the assembly ‘MpaAbp.EntityFramework’.
重新生成解决方案 重启VS 执行命令Enable-Migrations -Force
在与 SQL Server 建立连接时出现与网络相关的或特定于实例的错误。未找到或无法访问服务器。请验证实例名称是否正确并且 SQL Server 已配置为允许远程连接。
Update-Database -ConnectionStringName “default” //带上连接字符串
The project ‘MpaAbp.EntityFramework’ failed to build.
将MpaAbp.EntityFramework设为启动项
在多语句事务内不允许使用 CREATE DATABASE 语句。
Add-Migration前需要先创建好数据库
The Designer Code for this migration file includes a snapshot of your current Code First model. This snapshot is used to calculate the changes to your model when you scaffold the next migration. If you make additional changes to your model that you want to include in this migration, then you can re-scaffold it by running ‘Add-Migration MpaAbp’ again.
这是警告,之后可以update-database
Keyword not supported.
参数名: multipleactiveresultsets
将数据库连接字符串中 multipleactiveresultsets(或其他参数)这一项去掉
未解析成员“MySql.Data.MySqlClient.MySqlException,MySql.Data,…
是在尝试使用Mysql数据库可能出现的 !~/MpaAbp.EntityFramework\EntityFramework\MpaAbpDbContext.cs
类名上面加上[DbConfigurationType(typeof(MySqlEFConfiguration))]
其他诸如App.config文件中的配置如果按步骤来也不会有问题
The EntityFramework package is not installed on project ‘MpaAbp.Core’.
启动项目设为 MpaAbp.EntityFramework
The context cannot be used while the model is being created. This exception may be thrown if the context is used inside the OnModelCreating method or if the same context instance is accessed by multiple threads concurrently. Note that instance members of DbContext and related classes are not guaranteed to be thread safe.
连接字符串有问题 或 未按正确操作创建数据库实体
The project ‘MpaAbp.EntityFramework’ failed to build.
可能是代码中有错误 重新编译一下应该会提示报错
MpaAbp.Migrations.Configuration”不能用作泛型类型或方法“
删除Migrations文件夹中格式如:201911150647168_MpaAbp 的文件 重新编译
在与 SQL Server 建立连接时出现与网络相关的或特定于实例的错误。未找到或无法访问服务器。请验证实例名称是否正确并且 SQL Server 已配置为允许远程连接。 (provider: SQL Network Interfaces, error: 26 - 定位指定的服务器/实例时出错)
MpaAbp.Web设为启动项 (不是控制台那个默认项)
No language defined!
没有创建数据库 没有执行过Update-Database
如果都不是
那解决方案中应该有这个
控制台程序 用来生成的 App.config 里配置数据库连接 启动
这样就成功了
关键还是要充分理解部署步骤 每一步的含义 一味的面向错误去处理不可取