henkmollema / Dommel

CRUD operations with Dapper made simple.
MIT License
634 stars 100 forks source link

Implement Any method #186

Closed lucaxchaves closed 4 years ago

lucaxchaves commented 4 years ago

Can i implement a "Any" method, that returns true/false if there's any record on database that matches the expression?

public static bool Any<TEntity>(this IDbConnection connection, Expression<Func<TEntity, bool>> predicate, IDbTransaction? transaction = null)

Sample:


  public class Product
  {
        public int Id { get; set; }
        public bool Active { get; set; }
        public decimal SellPrice { get; set; }
  } 

connection.Any<Product>(p => p.Active && p.SellPrice > 100);

Will build the below query and check if there's any result.

 select 1 from products where active = 1 and sell_price > 100 limit 1