TFS 迁移 - 数据库项目循环依赖 [英] TFS Migration - Database Project Circular Dependency

查看:27
本文介绍了TFS 迁移 - 数据库项目循环依赖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为 Web 应用程序(还包含作为数据库项目的数据库)创建解决方案,然后使用应用程序的 Web 部署和 SQL 数据库的 DACPAC 从 TFS 部署它.不幸的是,该数据库正在使用由 3 部分组成的名称引用另一个数据库:

Select * From Database1.dbo.Table1

这迫使我将引用的数据库作为一个项目导入到引用它的应用程序的解决方案中,并将其设置为另一个项目中的引用,如下图所示:

问题是 Database1 正在引用 Database2,但 Database2 也在引用 Database1.

但是,当我尝试这样做时,出现以下错误:

我在网上搜索了一个解决方案,找到了两个:

1) 使用复合项目创建另一个包含两个数据库之间引用的第三个项目,然后使该项目引用另外两个.

请参阅此链接:

第一个解决方案需要我将所有数据库导入到每个应用程序的解决方案中(因为它们通过中央数据库相互链接).此外,每对项目(数据库、中央数据库)都会出现循环引用错误.

第二个解决方案可以工作,因为查询将被视为字符串,并且不需要我在解决方案中引用中央数据库,但是我不喜欢有这么多动态查询的想法.此外,将每个应用程序数据库中的所有查询替换为动态 SQL 也需要大量工作.

我想知道除了我提到的两个之外是否还有其他解决方案.

解决方案

解决循环引用问题的正确方法是使用复合项目.

一般来说,技巧"包括在每个数据库的复合项目中隔离所有共享对象(以及这些对象引用的对象;例如共享视图和在其定义中使用的所有表/函数).通过这种方式,每个数据库将由几个数据库项目定义:一个包含仅在其中使用的对象(基础),另一个包含要与其他数据库共享的所有对象(共享).然后,您必须将基础数据库项目与在其定义中需要其对象的共享项目相关联.

一张照片值一千字:

虚线代表相同数据库"引用(复合项目).实心的是常规"引用.

我用一个通用案例更新了我的博文:

SSDT:如何解决循环引用问题

I am trying to create a solution for a web application (that also contains the database as a database project) and then deploy it from TFS using web deploy for the application and DACPAC for the SQL database. Unfortunately the database is referencing another database using 3-part names:

Select * From Database1.dbo.Table1

This forces me to import the referenced database as a project in the solution for the application that references it and set it as a reference in the other project, as seen in the picture below:

The problem is that Database1 is referencing Database2, but Database2 is also referencing Database1.

However when I try to do this I get the following error:

I have searched online for a solution and found two:

1) Using composite projects to create another 3rd project that contains the references between the two databases and then make this project reference the other two.

See this link: Composite projects solution

2) Replacing all the 3-part names queries to dynamic SQL, such as this:

EXEC('Select * From Database1.dbo.Table1')

None of this solutions is good for me as I don't just have two databases referencing each other, but many databases referencing a central database that references them back, as seen in the schema below:

The first solution would require that I import all the databases into the solution of each application (as they are linked to each other via the Central Database). Also there would be the circular reference error for each pair of projects (Database, Central Database).

The second solution would work as the queries would be seen as strings and would not require me to reference the Central Database in the solution, however I do not like the idea of having so many dynamic queries. Also it would be way to much work to replace all queries with dynamic SQL in each application database.

I would like to know if there are any other solutions beside the two I have mentioned.

解决方案

The right way to solve the circular references problem is using the composite projects.

In general the "trick" consists to isolate all the shared objects (and the ones referenced by these; eg. a shared view and all the tables/functions used in its definition) in a composite project for each database. In this way each database will be defined by a couple of database projects: one containing the objects used only inside it (base) and one containing all the objects to be shared with the other databases (shared). Then you have to link a base database project with the shared one whose object are needed in its definitions.

One picture is worth a thousand words:

The dashed lines represent the "Same database" references (composite project). The solid ones are "regular" references.

I've updated my blog post with a generic case:

SSDT: How to Solve the Circular References Issue

这篇关于TFS 迁移 - 数据库项目循环依赖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆