Home > Blockchain >  Using Dapper with operator
Using Dapper with operator

Time:04-22

Good afternoon Dotnet Community, Since two days now i am working with this query on sql server database.

bellow is the query

var list_customers = conn.Query<customer>("select * from customer where DateInit>=:'d_debut' and DateInit<=:'d_fin';", new { d_debut=d_debut, d_fin=d_fin }).ToList();

the query should get all customers with DateInit<=d_debut and DateInit>=d_fin;

d_debut and d_fin are comming from the fonction arguments.

The query works fine form sql server db but with dapper from c# im getting this error:

SqlException: Incorrect syntax near ':'.

Can some help me how to do comparaison expression using Dapper.

Best Regards...

CodePudding user response:

Your SQL query is MS SQL like. You need dapper like. Try this:

var list_customers = conn.Query<customer>("select * from customer where DateInit>= @d_debut and DateInit<= @d_fin;", new { d_debut=d_debut, d_fin=d_fin }).ToList();
  • Related