Last active
August 3, 2018 16:43
-
-
Save gzamudio/4aee3f1142d19b1eeb9ffa71442e1bb4 to your computer and use it in GitHub Desktop.
This file contains 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
// src/Repositories/Database/DataBaseContext.cs | |
#region Using | |
using Microsoft.EntityFrameworkCore; | |
using MvcMovie.Models; | |
#endregion | |
namespace MvcMovie.Repositories.Database | |
{ | |
public class DataBaseContext : DbContext | |
{ | |
public DataBaseContext(DbContextOptions<DataBaseContext> options) : base(options) {} | |
public DbSet<Movie> Movies { get; set; } | |
protected override void OnModelCreating(ModelBuilder modelBuilder) | |
{ | |
base.OnModelCreating(modelBuilder); | |
} | |
} | |
} |
This file contains 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
// src/Models/Database/Movie.cs | |
using System; | |
namespace MvcMovie.Models.Database | |
{ | |
public class Movie | |
{ | |
public int ID { get; set; } | |
public string Title { get; set; } | |
public DateTime ReleaseDate { get; set; } | |
public string Genre { get; set; } | |
public decimal Price { get; set; } | |
} | |
} |
This file contains 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
namespace MvcMovie | |
{ | |
public class Startup | |
{ | |
// ... | |
public void ConfigureServices(IServiceCollection services) | |
{ | |
services.AddMvc(); | |
services.AddDbContext<DataBaseContext>(options => options.UseNpgsql(Configuration["ConnectionString"])); | |
services.AddScoped<DataBaseContext>(); | |
} | |
// ... | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment