TFS Migration - Database Project Circular Dependency

旧街凉风 提交于 2020-01-06 01:44:49

问题


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.


回答1:


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




回答2:


You can also create a dacpac out of the existing database and add that dacpac as the database reference. We did that using a "Schema" folder to store all of the dacpacs and updated/referenced those as needed.

http://schottsql.blogspot.com/2012/10/ssdt-external-database-references.html




回答3:


You can create another project that can be referenced Database1 and Database2 and this project handle calling between the two projects.

and let this project communicate with web application.



来源:https://stackoverflow.com/questions/34628967/tfs-migration-database-project-circular-dependency

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!