title: How to incorporate OpenQuery into an SSDT project (without SQL71501/'unresolved reference to object' errors)
body: <p>I have a Visual Studio SSDT project where one view references a linked server via 4 part naming. I have set up a project for the database on the linked server and created a reference from the main project to the "linked server" project, and all works fine.</p>
  
  <p>I have been instructed to use OpenQuery instead of 4 part naming convention because actually OpenQuery does run 2-3x faster than query via 4 part naming convention.</p>
  
  <p>However, when I change the view in SSDT to use open query, I get an error:
  Severity    Code    Description Project File    Line    Suppression State
  Error       SQL71501: View: [schema].[view] has an unresolved reference to object [LINKEDSERVER].</p>
  
  <p>I have tried defining [LINKEDSERVER] in a script in the project:</p>
  
  <pre><code>exec master.dbo.sp_addlinkedserver @server = N'LINKEDSERVER', @srvproduct=N'SQLSERVER', @provider=N'SQLNCLI', @datasrc=N'SERVERNAME'
  </code></pre>
  
  <p>And also tried adding same into the referenced project.</p>
  
  <blockquote>
    <p><strong>So, how to incorporate OpenQuery into an SSDT project without incurring SQL71501/'unresolved reference to object' errors?</strong></p>
  </blockquote>
  
  <p><a href="https://i.stack.imgur.com/XThlm.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/XThlm.png" alt="OpenQuery erroring whereas 4 part works fine"></a></p>