From 24d6832ec0c349896105da16342d1e7adb675a7c Mon Sep 17 00:00:00 2001 From: malimova Date: Wed, 8 May 2024 01:41:20 +0400 Subject: [PATCH] =?UTF-8?q?=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D1=8F=20+=20Migrations?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LabWork/LabWork/ContactViewModel.cs | 2 +- LabWork/LabWork/Database/Contact.cs | 2 +- LabWork/LabWork/Database/ContactsDatabase.cs | 4 +- LabWork/LabWork/Database/ContactsStorage.cs | 2 +- LabWork/LabWork/FormContacts.Designer.cs | 6 +-- .../20240507213755_Initial.Designer.cs | 49 +++++++++++++++++++ .../Migrations/20240507213755_Initial.cs | 36 ++++++++++++++ .../ContactsDatabaseModelSnapshot.cs | 46 +++++++++++++++++ LabWork/LabWork/Program.cs | 2 +- 9 files changed, 139 insertions(+), 10 deletions(-) create mode 100644 LabWork/LabWork/Migrations/20240507213755_Initial.Designer.cs create mode 100644 LabWork/LabWork/Migrations/20240507213755_Initial.cs create mode 100644 LabWork/LabWork/Migrations/ContactsDatabaseModelSnapshot.cs diff --git a/LabWork/LabWork/ContactViewModel.cs b/LabWork/LabWork/ContactViewModel.cs index 732c716..6257cf7 100644 --- a/LabWork/LabWork/ContactViewModel.cs +++ b/LabWork/LabWork/ContactViewModel.cs @@ -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; diff --git a/LabWork/LabWork/Database/Contact.cs b/LabWork/LabWork/Database/Contact.cs index 5b9f52b..f84357c 100644 --- a/LabWork/LabWork/Database/Contact.cs +++ b/LabWork/LabWork/Database/Contact.cs @@ -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 { diff --git a/LabWork/LabWork/Database/ContactsDatabase.cs b/LabWork/LabWork/Database/ContactsDatabase.cs index c5f0013..ebc1aa7 100644 --- a/LabWork/LabWork/Database/ContactsDatabase.cs +++ b/LabWork/LabWork/Database/ContactsDatabase.cs @@ -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 Contacts { set; get; } diff --git a/LabWork/LabWork/Database/ContactsStorage.cs b/LabWork/LabWork/Database/ContactsStorage.cs index c60d950..df97f7d 100644 --- a/LabWork/LabWork/Database/ContactsStorage.cs +++ b/LabWork/LabWork/Database/ContactsStorage.cs @@ -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 { diff --git a/LabWork/LabWork/FormContacts.Designer.cs b/LabWork/LabWork/FormContacts.Designer.cs index efbd17c..1adf890 100644 --- a/LabWork/LabWork/FormContacts.Designer.cs +++ b/LabWork/LabWork/FormContacts.Designer.cs @@ -5,7 +5,7 @@ /// /// Required designer variable. /// - private System.ContactModel.IContainer Contacts = null; + private System.ComponentModel.IContainer Contacts = null; /// /// 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); } diff --git a/LabWork/LabWork/Migrations/20240507213755_Initial.Designer.cs b/LabWork/LabWork/Migrations/20240507213755_Initial.Designer.cs new file mode 100644 index 0000000..089e8a9 --- /dev/null +++ b/LabWork/LabWork/Migrations/20240507213755_Initial.Designer.cs @@ -0,0 +1,49 @@ +// +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 + { + /// + 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("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ContactName") + .IsRequired() + .HasColumnType("text"); + + b.Property("Number") + .HasColumnType("double precision"); + + b.HasKey("Id"); + + b.ToTable("Contacts"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/LabWork/LabWork/Migrations/20240507213755_Initial.cs b/LabWork/LabWork/Migrations/20240507213755_Initial.cs new file mode 100644 index 0000000..57af8f8 --- /dev/null +++ b/LabWork/LabWork/Migrations/20240507213755_Initial.cs @@ -0,0 +1,36 @@ +using Microsoft.EntityFrameworkCore.Migrations; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace LabWork.Migrations +{ + /// + public partial class Initial : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Contacts", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + ContactName = table.Column(type: "text", nullable: false), + Number = table.Column(type: "double precision", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Contacts", x => x.Id); + }); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Contacts"); + } + } +} diff --git a/LabWork/LabWork/Migrations/ContactsDatabaseModelSnapshot.cs b/LabWork/LabWork/Migrations/ContactsDatabaseModelSnapshot.cs new file mode 100644 index 0000000..835374f --- /dev/null +++ b/LabWork/LabWork/Migrations/ContactsDatabaseModelSnapshot.cs @@ -0,0 +1,46 @@ +// +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("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ContactName") + .IsRequired() + .HasColumnType("text"); + + b.Property("Number") + .HasColumnType("double precision"); + + b.HasKey("Id"); + + b.ToTable("Contacts"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/LabWork/LabWork/Program.cs b/LabWork/LabWork/Program.cs index b4f749f..c975fe9 100644 --- a/LabWork/LabWork/Program.cs +++ b/LabWork/LabWork/Program.cs @@ -25,7 +25,7 @@ namespace LabWork { services.AddTransient(); services.AddTransient(); - services.AddTransient(); + //services.AddTransient(); services.AddTransient(); } }