简体   繁体   English

在本地使用SQL Server CE和在生产实体框架代码上使用SQL Server 2008?

[英]Use SQL Server CE Locally and SQL Server 2008 on Production Entity Framework Code First?

I am using EF Code first to generate my models. 我首先使用EF代码生成我的模型。 I have added SQL Server Compact Edition to my project and am using that as a DB locally. 我已将SQL Server Compact Edition添加到我的项目中,并将其用作本地数据库。

I want to configure the DataContext so that when I push to Production (based on the machine name) it instead would pull from a connection string in the Web Config and use a SQL Server 2008 DB. 我想配置DataContext,以便当我推送到Production(基于机器名称)时,它将从Web Config中的连接字符串中提取并使用SQL Server 2008 DB。

What is the easiest way to do this? 最简单的方法是什么? Basically my question is at what point do I need to add the conditional so that when it is deployed it pulls in the connection string and just works. 基本上我的问题是我需要在什么时候添加条件,以便在部署时它拉入连接字符串并且正常工作。

Is this even a recommended approach? 这甚至是推荐的方法吗?

My first thought is that you only need to deliver a different ConnectionString when you deploy your App.Config 我的第一个想法是,在部署App.Config时,您只需要提供不同的ConnectionString

Using different 'Solution Configurations' (Debug/Release/ etc.) there are possibilities to even automate this via with MSBuild. 使用不同的“解决方案配置”(调试/发布/等),甚至可以通过MSBuild自动执行此操作。

This discussion has one approach where you have multiple settings in the same config file. 讨论有一种方法,您在同一个配置文件中有多个设置。 Here the suggestion is to use multiple config files, one for each environment or use MSBuild to produce select a config file. 这里的建议是使用多个配置文件,每个环境一个或使用MSBuild生成选择配置文件。

using #IF DEBUG is another option but risky where a developer decides to test a release version and forgets they are running against a live system! 使用#IF DEBUG是另一种选择,但在开发人员决定测试发布版本并忘记它们是针对实时系统运行的时候会有风险!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 SQL Server CE 4实体框架4.3.1代码优先区分重音和区分大小写的搜索 - SQL Server CE 4 Entity Framework 4.3.1 Code First accent-insensitive and case-insensitive search 实体框架6.1.3和SQL Server CE 4.0-代码优先设置密码以保护sdf文件 - Entity Framework 6.1.3 and SQL Server CE 4.0 - Code First Setup a password to protect sdf file 外部SQL服务器上的实体框架代码优先 - Entity Framework Code First on external SQL server 实体框架6 / SQL Server CE 4 SaveChangesAsync() - Entity Framework 6 / SQL Server CE 4 SaveChangesAsync() SQL Server CE代码首次迁移问题 - SQL Server CE Code First migrations problems 实体框架4:SQL Server 2008的性能不佳 - Entity Framework 4 : Bad performance with SQL Server 2008 实体框架和SQL Server 2008 Express - Entity Framework & SQL Server 2008 Express 如何使用实体框架生成与SQL Server兼容的数据库(代码优先) - How to generate a SQL Server compatible database with Entity Framework (code first) SQL Server数据库转换为实体框架代码优先 - Converter of SQL Server DB to Entity Framework Code First 实体框架代码优先和SQL Server 2012序列 - Entity Framework Code First and SQL Server 2012 Sequences
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM