The context is being used in Code First mode with code that was generated from an EDMX file for either Database First or Model First development. This will not work correctly. To fix this problem do not remove the line of code that throws this exception. If you wish to use Database First or Model First, then make sure that the Entity Framework connection string is included in the app.config or web.config of the start-up project. If you are creating your own DbConnection, then make sure that it is an EntityConnection and not some other type of DbConnection, and that you pass it to one of the base DbContext constructors that take a DbConnection. To learn more about Code First, Database First, and Model First see the Entity Framework documentation here: http://go.microsoft.com/fwlink/?LinkId=394715
DbContext是我用t4模板生成的。
using System;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using Model;
public partial class Entities : DbContext
{
public Entities()
: base("name=sqlCONN")
{
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
throw new UnintentionalCodeFirstException();
}
public DbSet<Dept> Depts { get; set; }
public DbSet<OrderDetail> OrderDetails { get; set; }
public DbSet<Order> Orders { get; set; }
public DbSet<Role> Roles { get; set; }
public DbSet<User_Role> User_Role { get; set; }
public DbSet<User> Users { get; set; }
}
连接字符串之类的没问题
@祁临芯: 请问你是怎么解决的额?
@eez: 上面那个链接有用的,你去看看。
链接字符串错了吧
个人感觉,你是即用了Databasefrist的方式生成了,有用CodeFrist的写法,微软都提示你去看看CodeFrist的知识了,那就去白
干掉EF生成的东东,重新来一次。
这几天没来博客园,有点事情,搞不懂这玩意,
@祁临芯: 从来一次,相当于复位哇。
@幻天芒: 重来了,还是不行。。。
删除DbContext中的
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
throw new UnintentionalCodeFirstException();
}
这个方法