zoukankan      html  css  js  c++  java
  • MVC4建立DBContext的EF6数据

    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.NETFrameworkv4.0.30319aspnet_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.NETFramework64v4.0.30319aspnet_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>
  • 相关阅读:
    Django 报错RuntimeError: Model class apps.alarms.models.SendAlarmRecord doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.
    Go获取Windows下的窗口
    linux中得到当前目录指定文件或者目录的绝对路径
    关于在IDEA中使用maven的运行test目录下的main方法无法找到类的?
    数值变量互换的三种方式
    对于List和普通数组元素怎么去重的方法
    UE编辑器UltraEdit格式化XML数据
    java操作JSON字符串转换成对象的时候如何可以不建立实体类也能获取数据
    java设置RabbitMQ的消费处理出现:ConditionalRejectingErrorHandler : Execution of Rabbit message listener failed.
    org.springframework.http.converter.HttpMessageNotReadableException
  • 原文地址:https://www.cnblogs.com/hww9011/p/3917699.html
Copyright © 2011-2022 走看看