microsoft / DacFx

SQL Server database schema validation, deployment, and upgrade runtime. Enables declarative database development and database portability across SQL Server versions and environments.
https://aka.ms/sqlpackage-ref
MIT License
292 stars 15 forks source link

Unresolved reference error creating synonym on table and type with same name #445

Open zijchen opened 1 month ago

zijchen commented 1 month ago

Steps to Reproduce:

  1. Create database project with this script:
    
    create table abcd (id int);
    go

create type abcd from int; go

create synonym syn_abcd for abcd; go


2. Build will result in this warning:
> Build warning SQL71502: Synonym: [dbo].[syn_abcd] has an unresolved reference to object [dbo].[abcd].

This is just a min repro. The warning turns into an error when the objects are coming from dacpac/database references ([original VS feedback](https://developercommunity.visualstudio.com/t/MicrosoftDataToolsSchemaSqlTaskstar/10611580#T-ND10656191)).

This was likely caused by the change to fix #327. According to [the docs](https://learn.microsoft.com/en-us/sql/t-sql/statements/create-synonym-transact-sql?view=sql-server-ver16) you cannot create a synonym to a User Defined Type (technically you can but you won't be able to use it). We likely just have to update the place in DacFx code where it resolves synonym object references to ignore UDTs.

**Did this occur in prior versions?  If not - which version(s) did it work in?**
Worked in all versions prior to DacFx 162.2.111/SDK 0.1.15-preview

(DacFx/SqlPackage/SSMS/Azure Data Studio)