[英]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.