打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
Changing EF's default connection factory from LocalDb to Sql Server

When you create a new project that makes use of Entity Framework 5, you'll notice how it uses LocalDb by default now. But let's assume you have a fully working instance of Sql Server that you wish to work against instead of LocalDb. How do you tell EF to use it? Simple, modify your application's config file. If you are running a web service or a website, your config file is web.config. If you are running a console application or a windows application, look for app.config.

LocalDb

  <entityFramework>

    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">

      <parameters>

        <parameter value="v11.0" />

      </parameters>

    </defaultConnectionFactory>

  </entityFramework>

Now, replace that portion of the configuration to make use of Sql Server instead of LocalDb.

Sql Server

  <entityFramework>

    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework">

      <parameters>

        <parameter value="Data Source=.; Integrated Security=True; MultipleActiveResultSets=True" />

      </parameters>

    </defaultConnectionFactory>

  </entityFramework>

You only need to change the configuration to match your appropriate connection string.


David.

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
Entity Framewor使用问题总结
让EF飞一会儿:如何用Entity Framework 6 连接Sqlite数据库
SQL Server配置管理器”远程过程调用失败“的问题解决
MVC5 + EF6 简单示例
ASP.NET MVC 5 学习教程:创建连接字符串
VS2013自带的数据库SQL Server Express LocalDB使用介绍
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服