Simple, micro-orm to query MYSQL databases written in C#
[Table("users")]
public class User {
[Column("id")]
public int Id { get; init; }
[Column("name")]
public string Name { get; init; }
}
public void Search() {
var connection = new MysqlConnection(connectionString);
var result = connection.Query<User>("SELECT * FROM `users`");
_ = result.Data; // IEnumerable<User>
}Values conversion works like c# built-in conversions by default.
If you want to convert some type, must implement IConvertible<TSource, TValue> interface in converter class.
Example:
public class ItemTypeConverter : IConvertible<string, ItemType>
{
public ItemType Parse(string source)
{
return source[0] switch
{
's' => ItemType.Floor,
'i' => ItemType.Wall,
_ => throw new ArgumentOutOfRangeException(nameof(source), source, null)
};
}
public string Convert(ItemType value)
{
return value switch
{
ItemType.Floor => "s",
ItemType.Wall => "i",
_ => throw new ArgumentOutOfRangeException(nameof(value), value, null)
};
}
}