title: Execute stored function returning primitive in postgresql using entity framework core
body: <p>I had a project running on Postgresql. I used Entity framework to execute stored procedure that would return some value (long). </p>
  
  <pre><code> public override long GetHostSequenceNumber(byte hostId, byte srvId)
   {
      var hId = new Npgsql.NpgsqlParameter("@host_id", hostId);
      var sId = new Npgsql.NpgsqlParameter("@srv_id", srvId);
      var res = this.Database.SqlQuery&lt;long&gt;("select * from  dbo.bs_p_get_host_seqno( @host_id,@srv_id)", hId, sId).SingleOrDefault();
      return res;
    }
  </code></pre>
  
  <p>Briefly, lets say that this procedure searhes for some specific value in some tables. </p>
  
  <p>And it worked just fine. But now I switched to Core 2.0 and I can't find a way to do the same thing. I've read some articles, where they say to use FromSql, but I can't use it since I don't have any entities that I would add to DbContext. I also tried use ADO and execute SQL commands but I always get -1 in the results. </p>
  
  <pre><code>public override long GetHostSequenceNumber(byte hostId, byte srvId)
      {
          var hId = new Npgsql.NpgsqlParameter("@host_id", hostId);
          var sId = new Npgsql.NpgsqlParameter("@srv_id", srvId);
          var res = this.Database.ExecuteSqlCommand("select * from  bs_p_get_host_seqno(@host_id,@srv_id)", hId,sId);
          return res;
      }
  </code></pre>
  
  <p>But ExecuteSqlCommand also always returns -1 and it is int type and I don't know how to get the result that I need.</p>