53 lines
1.4 KiB
C#

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