Skip to content

Instantly share code, notes, and snippets.

@gzamudio
Last active August 3, 2018 16:43
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 gzamudio/4aee3f1142d19b1eeb9ffa71442e1bb4 to your computer and use it in GitHub Desktop.
Save gzamudio/4aee3f1142d19b1eeb9ffa71442e1bb4 to your computer and use it in GitHub Desktop.
// 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);
}
}
}
// 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; }
}
}
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