title: Execute storedprocedure that return 0 with entitiy-framework
body: <p>I have a stored procedure in my db that looks like this:</p>
  
  <pre><code>IF EXISTS (SELECT * FROM Table1)
  BEGIN
      -- select statement
  END
  </code></pre>
  
  <p>I am using this procedure to check if there is any data inside table1. Table1 is used as a queue on database side.</p>
  
  <p>In my C# application I am using the entity framework to execute this stored procedure. Method Looks like this:</p>
  
  <pre><code>using (DatabaseEntities db = new DatabaseEntities())
          {
              var result = db.ALL_GET_JOBS();
  
              if (result == null)
              {
                  Console.WriteLine("No new jobs");
              }
              else
              {
                  Console.WriteLine(string.Format("received {0} new jobs", result.Count()));
              }
          }
  </code></pre>
  
  <p>When I execute to procedure I get an exception telling me that one of my defined columns doesn't exists within the result. Yeah, because the procedure is returning 0. The exception is thrown before I reach the if statement.</p>
  
  <p>I already tried adding .DefaultIfEmpty(null) or .FirstOrDefault() to the call of the procedure, but as far as I can say, the error occurs during the evaluation of the result.</p>
  
  <p>Does any one of you have an idea how to handle a procedure that is returning 0 instead of a result set in entity Framework?</p>
  
  <p>bg
  Christoph</p>