Visual Studio 数据库项目无法通过同义词创建视图

发布于 2024-11-29 09:02:13 字数 693 浏览 2 评论 0原文

我遇到的情况是,我正在使用 Visual Studio 2010 数据库项目构建的新数据库,该项目定义了许多指向我们的旧版数据库的同义词

我们的计划是创建对这些同义词的视图;被引用的表很糟糕,因此视图会将数据改造成更好的格式;之后,我们将使用实体框架为这些视图提供 ORM(想法是,我们可以在迁移数据时将视图交换为真实表)。

问题:我可以毫无问题地在数据库项目中编写同义词脚本。但是,当我尝试创建引用这些同义词的视图时,我遇到了类似于以下内容的错误:

Error  1  SQL03006: View: [dbo].[Person] has an unresolved reference to object [dbo].[ma_contact].

...其中 [dbo].[Person] 是新视图,而 [ dbo].[ma_contact] 是旧表的同义词。

解决方法:将所有视图创建脚本放入 Script.PostDeployment.sql 中,手动执行 if-exists-then-drop-then-create 逻辑。

尽管目前还可以接受,但这并不理想。有人对如何“正确”地表达这些观点有任何想法吗?

I have the situation where I'm working in a new database, built using a Visual Studio 2010 database project, which has a number of synonyms defined which point to our legacy database.

Our plan is to create views over these synonyms; the tables being referenced are horrible, so the views will mangle the data into a better format; after that we will use Entity Framework to provide an ORM for these views (the idea being that we can then swap the views for real tables as we migrate data).

Problem: I can script the synonyms in the database project with no problems. However, when I try to create a view which references these synonyms, I am confronted with an error similar to:

Error  1  SQL03006: View: [dbo].[Person] has an unresolved reference to object [dbo].[ma_contact].

...where [dbo].[Person] is the new view and [dbo].[ma_contact] is the synonym for the legacy table.

Workaround: Place all view creation scripts in Script.PostDeployment.sql, doing the if-exists-then-drop-then-create logic manually.

This is less than ideal, although it's livable-with for now. Anyone have any ideas as to how to do these views "properly"?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

冷︶言冷语的世界 2024-12-06 09:02:13

您是否尝试过向原始数据库添加数据库引用?您必须将其格式提取到 dacpac(对于 SSDT SQL 项目)或 DBSchema 文件(对于 DB 项目)。完成后,将其存储在项目可以找到的某个位置。我们在数据库项目的根目录下使用了“Schemas”文件夹,以便所有项目都可以引用它。在您的项目中,右键单击“References”文件夹并添加数据库引用。搜索 DBSchema/Dacpac 文件并将其与数据库名称一起使用。这应该可以让您的同义词正确解析,以便您可以在视图中引用它。

Have you tried adding a database reference to your original database? You'd have to extract its format into either a dacpac (for SSDT SQL Projects) or a DBSchema file (for DB Projects). Once you've done that, store it in some place the project can find it. We used a "Schemas" folder at the root of our DB Projects so all projects could reference it. In your project, right click the "References" folder and add a Database Reference. Search for your DBSchema/Dacpac file and use that, along with the name of the database. That should let your synonym resolve properly so you can reference it in your views.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文