PetaPoco: How to use the SQL Like keyword ( WHERE Name LIKE '%@0%')
What is the corr开发者_StackOverflow社区ect syntax for this query?
var l=db.Fetch<article>("SELECT * FROM articles WHERE title LIKE '%@0%'", 'something');
Or should I use CHARINDEX
?
May be
var l=db.Fetch<article>("SELECT * FROM articles WHERE title LIKE @0", "%something%");
I haven't tried this, but I think it is worth trying:
var l=db.Fetch<article>("SELECT * FROM articles WHERE title LIKE @0", "%" + "something" + "%");
If you have done your mappings (wich the T4 will do for you) then you could infact do it like so:
var l=db.Fetch<article>("WHERE title LIKE @0", "%something%");
Saves some typing :)
Can try like this also
var l=db.Fetch<article>("WHERE title LIKE @0", "%" + "something" + "%");
No need to write Select * From article
, when you want to get all the fields. You are better off to use string.format
to include the wildcards
var l=db.Fetch<article>("WHERE title LIKE @0", string.Format("%{0}%", yourVariable));
Articulo articulo = new Articulo();
articulo = db.SingleOrDefault<Articulo>("SELECT TOP (1) * FROM [Articulos] WHERE [CodigoEmpresa] = @0 and [CodigoArticulo] LIKE @1 ", CodigoEmpresa, codigoArticulo + "%");
精彩评论