I have an SQLite database with an event table consisting of four columns: id (INT), timestamp (TEXT), level (TEXT) and message (TEXT). When I read back events, I want to convert the level values to corresponding LogLevel enum values. The text values are the same as the enum member names. How can I do this? I see that if I use Query<object> I get a list where I can enumerate through all rows and cast them before adding them to new Event struct values. But is this the best/easiest way to do this?
public struct Event
{
public Event(DateTime timestamp, LogLevel level, string message)
{
Timestamp = timestamp;
Level = level;
Message = message;
}
public DateTime Timestamp { get; }
public LogLevel Level { get; }
public string Message { get; }
}
public enum LogLevel
{
FATAL,
ERROR,
WARN,
INFO
}
public List<Event> GetNewEvents(uint rowId)
{
var events = _dbConnection.Query<Event>("SELECT * FROM events WHERE id >= @RowId;", new { RowId = rowId });
return events.ToList();
}