MVC4建立DBContext的EF6数据时
1.需要using System.Data.Entity;命名空间
2.此命名空间需要安装EntityFromwork.dll,此dll可以在项目——》管理NuGet程序包里联机搜索EntityFromwork并安装即可
3.建立类wenbingDBContext并继承DbContext,此时就需要上面的命名空间了
4.程序代码如下:
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Web;
 
namespace wenbing.Models
{
    public class wenbingDBContext : DbContext
    {
        public wenbingDBContext()
            : base("name=at_advertisement")
        { }
        public DbSet accounts { get; set; }
    }
}
5,在2中安装EntityFromwork成功后会在项目根目录下的web.config里面出现以下xml文件,如下红色xml
 
<configuration>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <appSettings>
    <add key="webpages:Version" value="2.0.0.0" />
    <add key="webpages:Enabled" value="false" />
    <add key="PreserveLoginUrl" value="true" />
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
  </appSettings>
  <connectionStrings>
    <add name="at_advertisement" connectionString="Server=mysql55.cloudsapp.cn;database=at_advertisement;port=3312;uid=root;password=159357;" />
  </connectionStrings>
  <system.web>
    <compilation debug="true" targetFramework="4.0" />
    <pages>
      <namespaces>
        <add namespace="System.Web.Helpers" />
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Routing" />
        <add namespace="System.Web.WebPages" />
      </namespaces>
    </pages>
  </system.web>
  <system.webServer>
    <validation validateIntegratedModeConfiguration="false" />
    <modules runAllManagedModulesForAllRequests="true" />
    <handlers>
      <remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
      <remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
      <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
      <add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
      <add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />
      <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
    </handlers>
  </system.webServer>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="v11.0" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
</configuration>

MVC4建立DBContext的EF6数据的更多相关文章

  1. [MVC4]ASP.NET MVC4+EF5(Lambda/Linq)读取数据

    继续上一节初始ASP.NET MVC4,继续深入学习,感受了一下微软的MVC4+EF5(EntityFramework5)框架的强大,能够高效的开发出网站应用开发系统,下面就看一下如何用MVC4+EF ...

  2. Hadoop建立IPC连接和数据读写

    建立IPC连接 IPC Client通过调用getConnection获取IPC连接,具体流程图如下: 服务器端的IPC连接代码分散在Listener和Server.Connection中. List ...

  3. [转][MVC4]ASP.NET MVC4+EF5(Lambda/Linq)读取数据

    本文转自:https://blog.csdn.net/dingxiaowei2013/article/details/29405687 继续上一节初始ASP.NET MVC4,继续深入学习,感受了一下 ...

  4. Hive表的建立和导入导出数据

    Hive是Hadoop的常用工具之一,Hive查询语言(HiveQL)的语法和SQL类似,基本实现了SQL-92标准. 1. 表的建立 编写以下的文件: USE test; DROP TABLE IF ...

  5. Android 建立手机与手表数据同步机制总结

    Android Wear 数据同步机制总结 当手机与手表建立蓝牙连接之后.数据就能够通过Google Play Service进行传输. 同步数据对象Data Item DataItem提供手机与手表 ...

  6. 【Spring学习笔记-MVC-4】SpringMVC返回Json数据-方式2

    <Spring学习笔记-MVC>系列文章,讲解返回json数据的文章共有3篇,分别为: [Spring学习笔记-MVC-3]SpringMVC返回Json数据-方式1:http://www ...

  7. EF6数据迁移

    当Moldes发生改变时 会提示数据上下文的模型已在数据库创建后发生改变,则需要重建数据库并数据迁移 在NuGet程序包管理控制台输入enable-migrations启用数据迁移 之后会提示&quo ...

  8. 在MySQL数据库建立多对多的数据表关系

    在数据库中,如果两个表的之间的关系为,多对多的关系,如:“学生表和课程表”,一个学生的可以选多门课,一门课也可以被多门学习选;根据数据库的设计原则,应当形成第三张关联表 步骤1:创建三张数据表Stud ...

  9. Asp.net MVC4 Step by Step (3)-数据验证

    ASP.NET MVC把数据验证集成到了请求处理过程中,控制器操作可以通过查询ModelState 来检查请求是否有效, 下面判断了ModelState的有效性后进行“保存或返回”操作.   [Htt ...

随机推荐

  1. Web Services

    Web Services 1.       Web Services基本规范概述 1.1.   什么是Web Services Web Services是为实现“基于Web无缝集成”的目标而提出的全新 ...

  2. python的bind函数

    # -*- coding:utf-8 -*- class Functor(object): def __init__(self, func, index=0, *args, **kwargs): se ...

  3. Cannot find module formidable

    今天按照例子学习安装 formidable 即使我-g全局安装,也不行.. 于是搜到了这句话.. 解决了 我也遇到这个问题,困扰了我一天,现在找到解决办法了.我在看这篇入门教程:http://node ...

  4. angular2 学习笔记 ( Form 表单 )

    refer : https://angular.cn/docs/ts/latest/guide/forms.html https://angular.cn/docs/ts/latest/cookboo ...

  5. 求帮看!!!!BZOJ 1014 [JSOI2008]火星人prefix

    1014: [JSOI2008]火星人prefix Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 4164  Solved: 1277[Submit] ...

  6. BZOJ 1021 [SHOI2008]Debt 循环的债务

    1021: [SHOI2008]Debt 循环的债务 Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 694  Solved: 356[Submit][S ...

  7. (转载)PHP array_merge() 函数

    (转载)http://www.w3school.com.cn/php/func_array_merge.asp PHP Array 函数 定义和用法 array_merge() 函数把两个或多个数组合 ...

  8. 【转】VS调试技巧

    [转自]http://blog.csdn.net/ghttzsqgm/article/details/5326894 http://blog.csdn.net/cadcisdhht/article/d ...

  9. HDOJ(HDU) 2090 算菜价(简单水题、)

    Problem Description 妈妈每天都要出去买菜,但是回来后,兜里的钱也懒得数一数,到底花了多少钱真是一笔糊涂帐.现在好了,作为好儿子(女儿)的你可以给她用程序算一下了,呵呵. Input ...

  10. 在linux下文件转码

    在linux下转码命令: iconv  -f utf-8 a.txt > b.txt