title: Entity Framework 6 context.Database.SqlQuery<bool>
body: <p>Probably a supereasy thing to fix.</p>
  
  <p>I need to make a raw SQL query to the database:</p>
  
  <pre><code>var blnOrders = (bool)db.Database.SqlQuery&lt;bool&gt;(@"SELECT 
      CASE WHEN ( EXISTS (SELECT 
          1 AS [C1]
          FROM [dbo].[Orders] AS [Extent1] WITH (TABLOCKX, HOLDLOCK)
          WHERE [Extent1].[OrderNumber] IS NOT NULL
      )) THEN cast(1 as bit) WHEN ( NOT EXISTS (SELECT 
          1 AS [C1]
          FROM [dbo].[Orders] AS [Extent2] WITH (TABLOCKX, HOLDLOCK)
          WHERE [Extent2].[OrderNumber] IS NOT NULL
      )) THEN cast(0 as bit) END AS [C1]
      FROM  ( SELECT 1 AS X ) AS [SingleRowTable1]")
  </code></pre>
  
  <p>A <code>DbRawSqlQuery&lt;bool&gt;</code> is returned from this. Trying to convert it to a <code>bool</code> and then using the variable gives me the following error:</p>
  
  <pre><code>Cannot implicitly convert type 'System.Data.Entity.Infrastructure.DbRawSqlQuery&lt;bool&gt;' to 'bool'
  </code></pre>
  
  <p>I don't know what I am doing wrong? I thought you could just cast it to a <code>bool</code>?</p>
  
  <p>Checked the docs <a href="https://msdn.microsoft.com/en-us/data/jj592907" rel="nofollow">here</a> but there's only an example using <code>SqlQuery&lt;string&gt;</code>.</p>