Last active
October 29, 2017 10:59
-
-
Save ozgurrgul/4b06e7097c0e95ac821090fdf7e64611 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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