Skip to content

Instantly share code, notes, and snippets.

@ozgurrgul
Last active October 29, 2017 10:59
Show Gist options
  • Save ozgurrgul/4b06e7097c0e95ac821090fdf7e64611 to your computer and use it in GitHub Desktop.
Save ozgurrgul/4b06e7097c0e95ac821090fdf7e64611 to your computer and use it in GitHub Desktop.
using Microsoft.EntityFrameworkCore;
namespace SimpleCrudApi.Entities
{
public class ApplicationDbContext : DbContext
{
public DbSet<User> Users { get; set; }
public DbSet<Announcement> Announcements { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseMySql(GetConnectionString());
}
private static string GetConnectionString()
{
const string databaseName = "simplecrud";
const string databaseUser = "root";
const string databasePass = "1";
return $"Server=localhost;" +
$"database={databaseName};" +
$"uid={databaseUser};" +
$"pwd={databasePass};" +
$"pooling=true;";
}
}
public class User
{
public int Id { get; set; }
public string Name { get; set; }
public string Surname { get; set; }
public string Email { get; set; }
}
public class Announcement
{
public int Id { get; set; }
public string Content { get; set; }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment