Probably a supereasy thing to fix.
I need to make a raw SQL query to the database:
var blnOrders = (bool)db.Database.SqlQuery<bool>(@"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]")
DbRawSqlQuery<bool> is returned from this. Trying to convert it to a
bool and then using the variable gives me the following error:
Cannot implicitly convert type 'System.Data.Entity.Infrastructure.DbRawSqlQuery<bool>' to 'bool'
I don't know what I am doing wrong? I thought you could just cast it to a
Checked the docs here but there's only an example using
Remove the (bool) as Ehsan told you, then
var res = await blnOrders.SingleAsync();