Simplified MySqlColumn by removing Default and Nullable. Added support for built in Nullable types. Bumped package version to 1.1.0
This commit is contained in:
@ -10,19 +10,22 @@ namespace MontoyaTech.MySqlPlus.Example
|
||||
[MySqlRowIndex("year", "year")]
|
||||
public class Car
|
||||
{
|
||||
[MySqlColumn(Id = true, Name = "id", PrimaryKey = true, AutoIncrement = true, Nullable = false)]
|
||||
[MySqlColumn(Id = true, Name = "id", PrimaryKey = true, AutoIncrement = true)]
|
||||
public ulong Id = 0;
|
||||
|
||||
[MySqlColumn("make")]
|
||||
public string Make = null;
|
||||
|
||||
[MySqlColumn("model", Nullable = false, Type = "VARCHAR(255)")]
|
||||
[MySqlColumn("model", Type = "VARCHAR(255)")]
|
||||
public string Model = "Unknown";
|
||||
|
||||
[MySqlColumn("year", Nullable = false)]
|
||||
[MySqlColumn("year")]
|
||||
public uint Year = 0;
|
||||
|
||||
[MySqlColumn("dateCreated", typeof(DateTimeToUnixConverter), DefaultValue = 0, Nullable = false)]
|
||||
[MySqlColumn("compact")]
|
||||
public bool? Compact = null;
|
||||
|
||||
[MySqlColumn("dateCreated", typeof(DateTimeToUnixConverter), DefaultValue = 0)]
|
||||
public DateTime DateCreated = DateTime.UtcNow;
|
||||
}
|
||||
|
||||
@ -30,18 +33,21 @@ namespace MontoyaTech.MySqlPlus.Example
|
||||
{
|
||||
var session = new MySqlSession("");
|
||||
|
||||
if (session.TableExists<Car>())
|
||||
session.DeleteTable<Car>();
|
||||
|
||||
session.CreateTable<Car>();
|
||||
|
||||
session.DeleteAll<Car>();
|
||||
|
||||
session.Insert(new Car() { Make = "Chevy", Model = "Camaro", Year = 2011 });
|
||||
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<Car>();
|
||||
|
||||
foreach (var car in cars)
|
||||
Console.WriteLine($"Make: {car.Make}, Model: {car.Model}, Year: {car.Year}, DateCreated: {car.DateCreated}");
|
||||
Console.WriteLine($"Make: {car.Make}, Model: {car.Model}, Year: {car.Year}, Compact: {car.Compact}, DateCreated: {car.DateCreated}");
|
||||
|
||||
cars[0].Make = "test";
|
||||
|
||||
|
Reference in New Issue
Block a user