- 搭建
新搭建好的EF,当你运行程序时报:
The model backing the 'SqlServerDbContext' context has changed since the database was created. Consider using Code First Migrations to update the database
这个时候如果你用 add-migration xxx 报如下错:
No migrations configuration type was found in the assembly 'webTest'. (In Visual Studio you can use the Enable-Migrations command from Package Manager Console to add a migrations configuration).
解决办法:去掉上下文 对象中的 : base("name=TestDb") 。执行成功后,再将代码还原。
/// <summary> /// 利用App.config中配置的字符串连接数据库 /// </summary> public SqlServerDbContext() : base("name=TestDb") { }
- 插入报错:An error occurred while updating the entries. See the inner exception for de
基本是实体问题,要么主键问题,要么字段多了少了,类型不对。
2. 报错:Object must implement IConvertible.
检查实体类型和字段是否一致