vs2012 MVC3 Project ObjectContext and DbContext

Source: Internet
Author: User

vs2012 MVC3 Project ObjectContext and DbContext2013-01-07 16:21:47Install good vs2012, began to learn vs2012 under the MVC, but in 2010 under the familiar context base class ObjectContext disappeared, replaced by DbContext, it is strange, some familiar methods are missing, such as: Entity object Attach method, Context of the Objectstatemanager object, are missing, strange, how to let the context object inherit ObjectContext instead of DbContext, can only check the data.
Baidu a day Chinese information, did not find, so on Google search English materials, and finally will find a solution to the problem solved.

Problem:
We move some projects from VS2010 to VS2012 if still using. NET 4.0 and not. NET 4.5
When I add a new EDMX, VS2012 use EF-5.0 but I ' d like continue-to-use the version 4.x it's the first point.
Second point The version 5.0, inherit from DbContext and not ObjectContext like version 4.x. With the version 5.0 I don't see any of the to pass the connection string as parameter.
How can I use version 4.x in VS2012, with the same EDMX designer behavior?
From the foreigner's problem can be seen, when using DbContext, need to replace the connection string is a problem ah, look at the solution:

Workaround:
As mentioned in the comments, you ' re really getting EF 4.4, not EF 5.0. However, confusingly, EF 4.4 in contained in the NuGet EntityFramework 5.0 package.
For your other question, your can open the EDMX in the designer, restore ' Code generation strategy ' from ' None ' to ' Default ", then in the Solution Explorer, remove the. tt files. Now you'll have yourobjectcontext again, and if your wish, you can remove the EntityFramework package from your project.
I ' m not sure if there's any-to-change-this-default behaviour of adding the NuGet package.

It's easy. Simply open the edmx file in Design view, change code generation policy to default in the Properties panel, and then delete the ". tt" file in Solution Manager. In view of the. designer.cs file, there is already generated code, and the parent class is already objectcontext, all the problems are OK.

vs2012 MVC3 Project ObjectContext and DbContext

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.