Search code examples
dapper

Check if record exists with Dapper ORM


What is the simplest way to check if record exists using the Dapper ORM?

Do I really need to define POCO objects for a query where I only want to check if a record exists?


Solution

  • int id = ...
    var exists = conn.ExecuteScalar<bool>("select count(1) from Table where Id=@id", new {id});
    

    should work...