I have a database table named Tags (Id, Name) from which I would like to select the ones where the name matches a name in a list. In SQL I would use something like:
Here is an another sample:
program.cs:
public static void Main(string[] args)
{
using (var db = new PetaPoco.Database("Northwind"))
{
var sql = "Select * from customers where Country in (@Countries)";
var countries = new { @Countries = new string[] { "USA", "Mexico" } };
var customers = db.Query(sql, countries);
foreach (var customer in customers)
{
Console.WriteLine("{0} - {1} from {2}", customer.CustomerID, customer.CompanyName, customer.Country);
}
}
}
customer.cs:
public class Customer
{
public string CustomerID { get; set; }
public string Address { get; set; }
public string City { get; set; }
public string CompanyName { get; set; }
public string ContactName { get; set; }
public string ContactTitle { get; set; }
public string Country { get; set; }
public string Fax { get; set; }
public string Phone { get; set; }
public string PostalCode { get; set; }
public string Region { get; set; }
}
App.config: (Connectionstring uses localdb connectionstring, so you might change it.)