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

  • 相关阅读:
    Django中实现加载渲染模版
    【干货】批量文件合拼 cat 命令的使用
    【Sql】获取数据库字段信息
    【C#】 TxtHelper
    【Css】鼠标
    【HTTP】H5唤醒支付宝
    【dotnet】程序集注入
    【OpenXml】excel 导入导出
    一、API​​网关
    【kafka】二、kafka的基本概念
  • 原文地址:https://www.cnblogs.com/zhaow/p/9754045.html
Copyright © 2011-2022 走看看