MicroOrm.Pocos.SqlGenerator icon indicating copy to clipboard operation
MicroOrm.Pocos.SqlGenerator copied to clipboard

Where between

Open fretelweb opened this issue 8 years ago • 1 comments

Hi I would like to now how can I filter a GetSelect between 2 dates

fretelweb avatar Dec 03 '16 22:12 fretelweb

Hi. I know this is a very basic feature but sadly the library doesn't support it out of the box. If you are using this library with the Dapper.DataRepositories library, what you can do is to extend the repository where you want to apply a filter like this and write your own sql statement or even better use a stored procedure.

Something like this: (lets say you are working with an "Orders" repository):

Define a new function on your repository contract, like this:

public IOrdersRepository: IDataRepository<Order>
{
     IEnumerable GetByDate(DateTime start, DateTime end);
}

And then implement your function on the repository, like this:

public OrdersRepository: DataRepository<Order>, IOrdersRepository
{
     public IEnumerable GetByDate(DateTime start, DateTime end)
     {
          return Connection.Query<Order>("... your sql or your store procedure ...", new { start, end });
     }
}

ElNinjaGaiden avatar Dec 03 '16 22:12 ElNinjaGaiden