Skip to content

Instantly share code, notes, and snippets.

@ArrowCase
Created June 15, 2019 04:51
Show Gist options
  • Save ArrowCase/cd9c3ad91b1eaf0e9038a5886e5225e7 to your computer and use it in GitHub Desktop.
Save ArrowCase/cd9c3ad91b1eaf0e9038a5886e5225e7 to your computer and use it in GitHub Desktop.
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Microsoft.EntityFrameworkCore;
namespace EnumRepro
{
public class ReproDbContext : DbContext
{
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if (!optionsBuilder.IsConfigured)
{
optionsBuilder.UseSqlite(@"Data Source=repro.db");
}
}
public DbSet<Model> Models { get; set; }
}
public enum State : byte
{
One,
Two,
Three
}
public class Model
{
[Key]
public int Id { get; set; }
[Required]
[Column(TypeName = "tinyint")]
public State State { get; set; }
}
public static class Program
{
public static void Main()
{
var dbContext = new ReproDbContext();
dbContext.Database.EnsureDeleted();
dbContext.Database.EnsureCreated();
dbContext.Models.Add(new Model());
dbContext.SaveChanges();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment