Skip to content

Instantly share code, notes, and snippets.

@dcomartin
Created November 8, 2023 19:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dcomartin/baec2f857cea7850422825b66a35e355 to your computer and use it in GitHub Desktop.
Save dcomartin/baec2f857cea7850422825b66a35e355 to your computer and use it in GitHub Desktop.
public class TestDbContext : DbContext
{
public DbSet<Order> Orders => Set<Order>();
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
var connectionString = "Server=localhost;Port=3307;Database=Demo;Uid=root;Pwd=root";
optionsBuilder.UseMySql(connectionString, ServerVersion.AutoDetect(connectionString));
optionsBuilder.LogTo(Console.WriteLine);
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Order>().HasKey(x => x.OrderId);
}
}
public class Order
{
[Key]
public int OrderId { get; set; }
public DateTime Date { get; set; }
public int CustomerId { get; set; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment