首页 新闻 会员 周边 捐助

EF问题 生成的DbContext报如下错误

0
悬赏园豆:40 [已解决问题] 解决于 2015-04-23 20:18

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; }
}

祁临芯的主页 祁临芯 | 菜鸟二级 | 园豆:251
提问于:2014-12-05 17:57
< >
分享
最佳答案
-1
收获园豆:40
Yu | 专家六级 |园豆:12990 | 2014-12-06 16:02

连接字符串之类的没问题 

祁临芯 | 园豆:251 (菜鸟二级) | 2014-12-08 11:52

@祁临芯: 请问你是怎么解决的额?

eez | 园豆:96 (初学一级) | 2015-07-15 14:43

@eez: 上面那个链接有用的,你去看看。

祁临芯 | 园豆:251 (菜鸟二级) | 2015-07-17 15:02
其他回答(4)
0

链接字符串错了吧

刘宏玺 | 园豆:14020 (专家六级) | 2014-12-05 20:01
0

个人感觉,你是即用了Databasefrist的方式生成了,有用CodeFrist的写法,微软都提示你去看看CodeFrist的知识了,那就去白

Halower | 园豆:1723 (小虾三级) | 2014-12-05 22:14
0

干掉EF生成的东东,重新来一次。

幻天芒 | 园豆:37207 (高人七级) | 2014-12-06 09:06

这几天没来博客园,有点事情,搞不懂这玩意,

支持(0) 反对(0) 祁临芯 | 园豆:251 (菜鸟二级) | 2014-12-08 10:47

@祁临芯: 从来一次,相当于复位哇。

支持(0) 反对(0) 幻天芒 | 园豆:37207 (高人七级) | 2014-12-08 11:15

@幻天芒: 重来了,还是不行。。。

支持(0) 反对(0) 祁临芯 | 园豆:251 (菜鸟二级) | 2014-12-08 11:52
0

删除DbContext中的

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
throw new UnintentionalCodeFirstException();
}

这个方法

hooliy | 园豆:231 (菜鸟二级) | 2015-02-07 12:53
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册