实体框架4.1代码先冻结 [英] Entity Framework 4.1 Code First Freeze

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

问题描述

我遇到了麻烦EF 4.1我的电脑上工作。这似乎是有些问题,我的数据库设置。我尝试了这种简单的演练:
http://blogs.msdn.com/b/adonet/archive/2011/03/15/ef-4-1-code-first-walkthrough.aspx

I'm having trouble getting EF 4.1 working on my computer. It seems to be some problem with my database settings. I was trying out this simple walkthrough: http://blogs.msdn.com/b/adonet/archive/2011/03/15/ef-4-1-code-first-walkthrough.aspx

但是,当它到达db.Categories.Add(食物);它只是冻结。

But when it reaches db.Categories.Add(food); it just freeze.

我有一个正常的SQL Server 2008 R2安装,而不是SQL Express的。此外,还似乎有一些问题,而不是创建一个密度纤维板直接连接到本地主机的SQL Server的文件。

I have a normal SQL Server 2008 R2 installed, not SQL Express. There also seems to be some problems with creating .mdf files instead of a direct connection to the localhost SQL server.

我也尝试添加一个实体模型与数据库连接,但这似乎并没有工作。 。做任何人有任何指针我

I've also tried adding an entity model with a database connection, but this does not seem to work. Do anyone have any pointers for me.

感谢您的答案:)

编辑:
我现在得到了System.Data.ProviderIncompatibleException供应商没有返回ProviderMaifestToken字符串

edit: I now get a System.Data.ProviderIncompatibleException with "Vendor returned no ProviderMaifestToken-string"

推荐答案

我发现这个问题。这些教程不包含有关,我需要使它工作一些重要调整的信息。

I found the problem. These tutorials do not contain information about some vital adjustments that I needed to make it work.

1)您的应用程序必须有一个包含与同一个命名的ConnectionString一个app.config名称作为类,从继承的DbContext。在我的情况TestEF_CF.ProductContext。

1) Your application must have an App.config containing a connectionstring named with the same name as your class that inherited from DbContext. In my case "TestEF_CF.ProductContext".

2)你开始使用之前,数据库无法被创建。只需设置初始目录到您想要实体框架创建时,它自动创建该数据库的名称。

2) The database cannot be created before you start to use it. Just set the Initial Catalogue to the name you want Entity Framework to create when it autocreate the database.

在我这样做,它工作正常。我的第一步骤还得到了,却得到了当我试图保存到数据库中的一个例外。当EF自动创建数据库一切正常。

Once I did this, it worked properly. I got further with the first step, but got an exception when I tried to save to the database. When EF autocreated the database everything worked fine.

一件事,可能使人们更多的问题在我的开发环境可能是事实,我不能直接使用当地的MDF文件。还是它不会伤害如果EF团队可以分享这些细节更加开放比他们现在做的,它会救我(或我们)有些无奈。

One thing that may have made it more problematic on my development environment could be the fact that I cannot use local mdf files directly. Still it would not hurt if the EF team could share these details more open than they do now, it would save me (or us) some frustration.

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

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