public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.AddEntityFramework()
.AddSqlServer()
.AddDbContext<WorldContext>();
In Models\WoldContext.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Data.Entity;
namespace aspnet5.Models
{
public class WorldContext: DbContext
{
public WorldContext()
{
Database.EnsureCreated();
}
public DbSet<Trip> Trips { get; set; }
public DbSet<Stop> Stops { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
var connString = Startup.Configuration["Data:WorldContextConnection"];
optionsBuilder.UseSqlServer(connString);
base.OnConfiguring(optionsBuilder);
}
}
}
No comments:
Post a Comment