实体框架无意codeFirstException [英] Entity Framework UnintentionalCodeFirstException

查看:130
本文介绍了实体框架无意codeFirstException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个MVC 4项目设置和使用产生的实体框架所有的模型类。然后,我添加了一个类,并将其命名一样MyProjectEntities级,并使其部分,所以我可以在这个类中加入个性化的方法。我加了一大堆的方法来查询数据库,在这个类和它建立的罚款。当我把这些方法虽然我得到意外codeFirstException。我不知道我做了什么错了?

I have a MVC 4 project set up and generated all the model classes using Entity Framework. Then I added a class and named it same as "MyProjectEntities" class and made it partial so I can add personalized methods in that class. I added bunch of methods to query database in this class and it builds fine. When I call these methods though I get UnintentionalCodeFirstException. I'm not sure what did I do wrong?

推荐答案

您需要提供正确的连接字符串。不只是普通的数据源=类型的字符串。

You need to provide the correct connection string. Not just the normal "Data Source=" type strings.

您将有开头的连接字符串元数据=在您的配置文件,使用那一个。

You will have a connection string that starts with "metadata=" in your config file, use that one.

这篇关于实体框架无意codeFirstException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆