zoukankan      html  css  js  c++  java
  • MVC4中使用EntityFramework

    首先,MVC4不支持EntityFramwok 6版本,如果安装了EntityFramwok 6,则vs不会自动引用dll和修改web.config配置。
    先删除旧的版本,执行指令:
    Uninstall-Package EntityFramework.zh-Hans
    Uninstall-Package EntityFramework  [-force]
    如:

     
    然后,
    通过NuGet安装EntityFramwok,可以指定要使用的版本,如(MVCEF1为项目名称):
    Install-Package EntityFramework -ProjectName MVCEF1 -Version 5.0

    执行成功后,web.config配置如下:
    <configSections>
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    </configSections>
    ......
    <entityFramework>
    <contexts>
      <context type="MVCEF1.DAL.AccountContext,MVCEF1">
        <databaseInitializer type="MVCEF1.DAL.AccountInitializer,MVCEF1"></databaseInitializer>
      </context>
    </contexts>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
    </entityFramework>


    参考:
    http://www.mamicode.com/info-detail-128217.html

  • 相关阅读:
    Python自动化运维之1、Python入门
    Github使用教程
    Windows 托盘区域显示图标
    VS 2013 打包程序教程
    UML类图简单介绍
    crontab定时任务
    软硬链接的区别和重点
    linux运维之NFS服务器配置
    怎么样让Win10可以ping通?
    VM虚拟机Linux克隆后网卡的相关操作!
  • 原文地址:https://www.cnblogs.com/zhaow/p/9754045.html
Copyright © 2011-2022 走看看