using MySql.Data.MySqlClient; using System; namespace MontoyaTech.MySqlPlus.Example { public class Program { [MySqlRow("cars")] [MySqlRowIndex("model_year", "model", "year")] [MySqlRowIndex("year", "year")] public class Car { [MySqlColumn(Id = true, Name = "id", PrimaryKey = true, AutoIncrement = true)] public ulong Id = 0; [MySqlColumn("make")] public string Make = null; [MySqlColumn("model", Type = "VARCHAR(255)")] public string Model = "Unknown"; [MySqlColumn("year")] public uint Year = 0; [MySqlColumn("compact")] public bool? Compact = null; [MySqlColumn("dateCreated", typeof(DateTimeToUnixConverter), DefaultValue = 0)] public DateTime DateCreated = DateTime.UtcNow; } public static void Main(string[] args) { var session = new MySqlSession(""); if (session.TableExists()) session.DeleteTable(); session.CreateTable(); session.DeleteAll(); session.Insert(new Car() { Make = "Chevy", Model = "Camaro", Year = 2011, Compact = true }); session.Insert(new Car() { Make = "GMC", Model = "Sierra", Year = 2000 }); var cars = session.GetAll(); foreach (var car in cars) Console.WriteLine($"Make: {car.Make}, Model: {car.Model}, Year: {car.Year}, Compact: {car.Compact}, DateCreated: {car.DateCreated}"); cars[0].Make = "test"; session.Update(cars[0]); foreach (var car in cars) session.Delete(car); session.DeleteTable(); Console.WriteLine("Done."); Console.ReadLine(); } } }