using Microsoft.Data.Sqlite;
namespace SmartphonesAppCore;
public class Class1
{
static SqliteConnection Connection = new SqliteConnection("DataSource=app.db");
public static List<Smartphone> GetSmartphones()
{
Dapper.DefaultTypeMap.MatchNamesWithUnderscores = true;
var smartphones = connection.Query<Smartphone, Model, Shop, Smartphone>(
@"SELECT * FROM smartphones
INNER JOIN models ON models.id = smartphones.model_id
INNER JOIN shops ON shops.id = smartphones.shop_id",
(smartphone, model, shop) =>
{
smartphone.Model = model;
smartphone.Shop = shop;
return smartphone;
}
);
}
}