Why My Postgresql query could not find the data in Net Core 6?

winanjaya 146 Reputation points
2023-08-07T15:21:19.0266667+00:00

I have a query of Postgresql-14 as below, the record was found if I run it on DBeaver 23.1.4.

I use:

  • Dapper 2.0.143
  • Npgsql 7.0.4
  • Npgsql.EntityFrameworkCore.PostgreSQL 7.0.4

What I don't understand is why it works properly on DBeaver 23.1.4?

I copy the query into a string variable named "sql", but I did not find the record if I run it on my Net Core 6 (C#) code, what I missed?

My C# code is below:

using (var dr = conn.ExecuteReader(sql, new { }))
{
   if (dr.Read())
   {
     double totalUsage = dr.GetDouble(dr.GetOrdinal("totalUsage"));
   }
}

I also have tried below, but result returns null

var result = conn.Query(sql, new { }).SingleOrDefault(); 

Developer technologies .NET Entity Framework Core
Developer technologies .NET Other
Developer technologies C#
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.