zoukankan      html  css  js  c++  java
  • vs2012 mvc3项目ObjectContext与DBContext .

    安装好vs2012,开始学习vs2012下的mvc,可是在2010下熟悉的上下文基类ObjectContext不见了,取而代之的是DBContext,很是奇怪,一些熟悉的方法不见了,如:实体对象的Attach方法,上下文的ObjectStateManager对象,都不见了,奇怪,如何让上下文对象继承ObjectContext而不是DBContext,只能查资料了。

    百度了一天中文资料,没有找到,于是上谷歌搜英文资料,终于会找到了解决的方法,问题解决了。

    问题:

    We move some projects from VS2010 to VS2012 but still using .NET 4.0 and not .NET 4.5

    When I add an 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 way to pass the connection string as parameter.

    How can I use version 4.x in VS2012, with the same EDMX designer behavior ?

    从老外的问题中可以看出,使用DBContext时,需要替换连接字符串还是个问题呀,下面看看解决的办法吧:

    解决办法:

    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, you 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 you wish, you can remove the EntityFramework package from your project.

    I'm not sure if there's any way to change this default behaviour of adding the NuGet package.

    很简单了只需要在设计视图中打开EDMX文件,在属性面板中将“代码生成策略”改为“默认”,然后将解决方案管理器中的“.tt”文件删除,在查看.designer.cs文件,已经有生成的代码了,并且父类已经是ObjectContext了,一切问题都OK了。

  • 相关阅读:
    2012的目标
    让顺丰快递给折腾了,昨晚发的快递,现在还没挪地方
    做的FM收音机终于交工,老婆验收完毕
    C语言宏定义使用技巧
    20棵树植树问题
    C简单实现动态2维数组
    运动量测试
    #pragma pack(n)的含义及其用法
    回调函数
    ubuntu 全局配置文件
  • 原文地址:https://www.cnblogs.com/zcm123/p/2918721.html
Copyright © 2011-2022 走看看