日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > c/c++ >内容正文

c/c++

MVC4建立DBContext的EF6数据

發布時間:2025/1/21 c/c++ 86 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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.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>


轉載于:https://blog.51cto.com/hww9011/1541227

總結

以上是生活随笔為你收集整理的MVC4建立DBContext的EF6数据的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。