Добавил миграцию для создания базы данных

parent c161a0c9
// <auto-generated />
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using MyCities.Models;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
namespace MyCities.Migrations
{
[DbContext(typeof(MyCitiesDbContext))]
[Migration("20190619144333_InitialMigration")]
partial class InitialMigration
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.SerialColumn)
.HasAnnotation("ProductVersion", "2.1.1-rtm-30846")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
modelBuilder.Entity("MyCities.Models.City", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd();
b.Property<string>("Country");
b.Property<string>("Name");
b.Property<int>("Population");
b.HasKey("Id");
b.ToTable("Cities");
});
modelBuilder.Entity("MyCities.Models.Person", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd();
b.Property<string>("AvatarImagePath");
b.Property<string>("FullName");
b.Property<string>("NickName");
b.HasKey("Id");
b.ToTable("Persons");
});
#pragma warning restore 612, 618
}
}
}
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
namespace MyCities.Migrations
{
public partial class InitialMigration : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Cities",
columns: table => new
{
Id = table.Column<int>(nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.SerialColumn),
Name = table.Column<string>(nullable: true),
Country = table.Column<string>(nullable: true),
Population = table.Column<int>(nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Cities", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Persons",
columns: table => new
{
Id = table.Column<int>(nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.SerialColumn),
FullName = table.Column<string>(nullable: true),
NickName = table.Column<string>(nullable: true),
AvatarImagePath = table.Column<string>(nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Persons", x => x.Id);
});
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Cities");
migrationBuilder.DropTable(
name: "Persons");
}
}
}
// <auto-generated />
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using MyCities.Models;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
namespace MyCities.Migrations
{
[DbContext(typeof(MyCitiesDbContext))]
partial class MyCitiesDbContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.SerialColumn)
.HasAnnotation("ProductVersion", "2.1.1-rtm-30846")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
modelBuilder.Entity("MyCities.Models.City", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd();
b.Property<string>("Country");
b.Property<string>("Name");
b.Property<int>("Population");
b.HasKey("Id");
b.ToTable("Cities");
});
modelBuilder.Entity("MyCities.Models.Person", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd();
b.Property<string>("AvatarImagePath");
b.Property<string>("FullName");
b.Property<string>("NickName");
b.HasKey("Id");
b.ToTable("Persons");
});
#pragma warning restore 612, 618
}
}
}
......@@ -2,6 +2,7 @@ namespace MyCities.Models
{
public class City
{
public int Id { get; set; }
public string Name { get; set; }
public string Country { get; set; }
public int Population { get; set; }
......
using Microsoft.EntityFrameworkCore;
namespace MyCities.Models
{
public class MyCitiesDbContext : DbContext
{
public DbSet<City> Cities { get; set; }
public DbSet<Person> Persons { get; set; }
public MyCitiesDbContext(DbContextOptions<MyCitiesDbContext> options) : base(options)
{
}
}
}
......@@ -2,6 +2,7 @@ namespace MyCities.Models
{
public class Person
{
public int Id { get; set; }
public string FullName { get; set; }
public string NickName { get; set; }
public string AvatarImagePath { get; set; }
......
......@@ -6,6 +6,9 @@
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL">
<Version>2.1.1.1</Version>
</PackageReference>
</ItemGroup>
</Project>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using MyCities.Models;
......@@ -33,6 +29,9 @@ namespace MyCities
options.MinimumSameSitePolicy = SameSiteMode.None;
});
string connectionString = Configuration.GetConnectionString("Default");
services.AddDbContext<MyCitiesDbContext>(options => options.UseNpgsql(connectionString));
services.AddSingleton<ICityRepository, InMemoryCityRepository>();
services.AddSingleton<IPersonRepository, InMemoryPersonRepository>();
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
......
{
"ConnectionStrings": {
"Default": "Host=localhost;Database=MyCities;Username=postgres;Password=qwerty"
},
"Logging": {
"LogLevel": {
"Default": "Warning"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment