开发和生产数据库

编程入门 行业动态 更新时间:2024-10-27 22:27:35
本文介绍了开发和生产数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我和我的团队当前正在做一个项目,我们正在使用Entity Framework 4.1(代码优先).我们想编写一些测试,但是我们不希望它们在我们的主数据库上运行,因为我们在新加坡有一个团队为我们所做的事情编写客户端,并且他们一直在访问该数据库.

I and my team are currently doing a project, where we are using Entity Framework 4.1 (Code First). We want to write some tests, but we don't want them to run on our primary database, as we have a team in Singapore writing a client for what we do, and they are hitting that database constantly.

因此,为了避免在运行测试时造成干扰,我们希望使用其他数据库进行测试.使用实体框架时,我们如何处理第二个数据库?我们需要一个(至少)半自动的解决方案,因此我们不必在每次需要运行测试时都弄弄Web.config.

So to avoid disturbance when running our tests, we would like to have a different database for testing. How do we handle a second database when using Entity Framework? We want a solution that is semi-automatic (at least), so we don't have to fiddle around with Web.config each time we need to run tests.

推荐答案

弄乱web.config的过程可能容易出错……除非您使用的是 web.config转换即是.

Fiddling around with the web.config can a process that is prone to error... unless you are using web.config Transformations that is.

我将在Visual Studio中为您的项目创建一个新配置测试",它可以是现有开发配置的副本(或调试/发行版,无论如何).然后,在解决方案资源管理器中右键单击您的Web.config文件,然后单击添加配置转换.按照此处的说明操作,以了解如何编写转换文件.如果您只需要更改测试环境的EF连接字符串,它将在web.Test.config中看起来像这样:

I would create a new configuration, "Test" for your project in Visual Studio... it can be a copy of your existing development configuration (or Debug / Release, whatever). Then, right click your Web.config file in Solution Explorer and click Add Config Transforms. Follow the instructions here on how to write a transform file. If you only need to change the EF connection string for the test environment it would look something like this in web.Test.config:

<?xml version="1.0"?> <configuration xmlns:xdt="schemas.microsoft/XML-Document-Transform"> <connectionStrings> <add name="AdventureWorksEntities" connectionString="metadata=.\AdventureWorks.csdl|.\AdventureWorks.ssdl|.\AdventureWorks.msl; provider=System.Data.SqlClient;provider connection string='Data Source=TestDB; Initial Catalog=AdventureWorks;Integrated Security=True;Connection Timeout=60; multipleactiveresultsets=true'" providerName="System.Data.EntityClient" xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/> </connectionStrings>

要运行测试,只需确保在正确的配置下进行构建.

Just be sure to build under the correct configuration when you want to run your tests.

还有一个Visual Studio加载项 SlowCheetah 这使得整个过程在IDE中非常无缝.

There is also a Visual Studio Add-in SlowCheetah Which makes this whole process very seamless from within the IDE.

更多推荐

开发和生产数据库

本文发布于:2023-10-24 09:05:16,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1523521.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据库

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!