исправления + Migrations

This commit is contained in:
malimova 2024-05-08 01:41:20 +04:00
parent db6fa68cae
commit 24d6832ec0
9 changed files with 139 additions and 10 deletions

View File

@ -1,6 +1,6 @@
using System;
using System.Collections.Generic;
using System.ContactModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

View File

@ -4,7 +4,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using LabWork.Interfaces;
using System.ContactModel.DataAnnotations;
using System.ComponentModel.DataAnnotations;
namespace LabWork.Database
{

View File

@ -1,7 +1,7 @@
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.ContactModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@ -19,8 +19,6 @@ namespace LabWork.Database
base.OnConfiguring(OptionsBuilder);
AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);
AppContext.SetSwitch("Npgsql.DisableDateTimeInfinityConversions", true);
}
public virtual DbSet<Contact> Contacts { set; get; }

View File

@ -4,7 +4,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using LabWork.Interfaces;
using System.ContactModel;
using System.ComponentModel;
namespace LabWork.Database
{

View File

@ -5,7 +5,7 @@
/// <summary>
/// Required designer variable.
/// </summary>
private System.ContactModel.IContainer Contacts = null;
private System.ComponentModel.IContainer Contacts = null;
/// <summary>
/// Clean up any resources being used.
@ -33,7 +33,7 @@
buttonUpd = new Button();
buttonRef = new Button();
buttonDel = new Button();
((System.ContactModel.ISupportInitialize)dataGridView).BeginInit();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
SuspendLayout();
//
// dataGridView
@ -95,7 +95,7 @@
Controls.Add(dataGridView);
Name = "FormContacts";
Text = "Менеджер контактов";
((System.ContactModel.ISupportInitialize)dataGridView).EndInit();
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
ResumeLayout(false);
}

View File

@ -0,0 +1,49 @@
// <auto-generated />
using LabWork.Database;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace LabWork.Migrations
{
[DbContext(typeof(ContactsDatabase))]
[Migration("20240507213755_Initial")]
partial class Initial
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "8.0.4")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("LabWork.Database.Contact", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("ContactName")
.IsRequired()
.HasColumnType("text");
b.Property<double>("Number")
.HasColumnType("double precision");
b.HasKey("Id");
b.ToTable("Contacts");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,36 @@
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace LabWork.Migrations
{
/// <inheritdoc />
public partial class Initial : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Contacts",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
ContactName = table.Column<string>(type: "text", nullable: false),
Number = table.Column<double>(type: "double precision", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Contacts", x => x.Id);
});
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Contacts");
}
}
}

View File

@ -0,0 +1,46 @@
// <auto-generated />
using LabWork.Database;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace LabWork.Migrations
{
[DbContext(typeof(ContactsDatabase))]
partial class ContactsDatabaseModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "8.0.4")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("LabWork.Database.Contact", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("ContactName")
.IsRequired()
.HasColumnType("text");
b.Property<double>("Number")
.HasColumnType("double precision");
b.HasKey("Id");
b.ToTable("Contacts");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -25,7 +25,7 @@ namespace LabWork
{
services.AddTransient<IContactStorage, ContactStorage>();
services.AddTransient<IContactLogic, ContactLogic>();
services.AddTransient<FormContact>();
//services.AddTransient<FormContact>();
services.AddTransient<FormContacts>();
}
}