добавлен индексатор и проведены тесты
This commit is contained in:
parent
7baba7c9b2
commit
ec58c36e23
@ -1,6 +1,7 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using SUBD;
|
||||
using SUBD.Models;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace Lab_5
|
||||
{
|
||||
@ -85,7 +86,11 @@ namespace Lab_5
|
||||
public static void GetFamalyMember()
|
||||
{
|
||||
using Context context = new();
|
||||
Stopwatch stopwatch = new();
|
||||
stopwatch.Start();
|
||||
var members = context.FamalyMembers.ToList();
|
||||
stopwatch.Stop();
|
||||
Console.WriteLine($"Время пррошло:{stopwatch.Elapsed.TotalMilliseconds}");
|
||||
if (members.Count == 0)
|
||||
{
|
||||
Console.WriteLine("Список членов семьи пуст");
|
||||
@ -338,15 +343,50 @@ namespace Lab_5
|
||||
}
|
||||
}
|
||||
|
||||
public static void Truncate()
|
||||
public static void TestAdd()
|
||||
{
|
||||
using Context context = new();
|
||||
context.SourcesIncome.RemoveRange(context.SourcesIncome);
|
||||
context.Incomes.RemoveRange(context.Incomes);
|
||||
context.CategorysExpenses.RemoveRange(context.CategorysExpenses);
|
||||
context.Expenses.RemoveRange(context.Expenses);
|
||||
context.FamalyMembers.RemoveRange(context.FamalyMembers);
|
||||
Console.WriteLine("База данных очищена");
|
||||
Random r = new();
|
||||
List<FamalyMember> members = new();
|
||||
for (int i = 0; i < 1000; i++)
|
||||
{
|
||||
var newMember = new FamalyMember()
|
||||
{
|
||||
Name = r.Next(1000).ToString()
|
||||
};
|
||||
members.Add(newMember);
|
||||
}
|
||||
Stopwatch stopwatch = new();
|
||||
stopwatch.Start();
|
||||
context.FamalyMembers.AddRange(members);
|
||||
stopwatch.Stop();
|
||||
Console.WriteLine($"Вставка прошла. Времени затрачено: {stopwatch.Elapsed.TotalMilliseconds}");
|
||||
}
|
||||
|
||||
public static void TestReadById()
|
||||
{
|
||||
using Context context = new();
|
||||
Random r = new();
|
||||
int Id = r.Next(1000);
|
||||
Stopwatch stopwatch = new();
|
||||
stopwatch.Start();
|
||||
var records = context.FamalyMembers.Where(x => x.Id == Id).ToList();
|
||||
stopwatch.Stop();
|
||||
Console.WriteLine($"Поиск по условию завершен. Времени затрачено: {stopwatch.Elapsed.TotalMilliseconds} мс");
|
||||
}
|
||||
|
||||
public static void TestDelete()
|
||||
{
|
||||
using Context context = new();
|
||||
Random r = new();
|
||||
List<FamalyMember> famalyMembers = context.FamalyMembers.ToList();
|
||||
Stopwatch stopwatch = new();
|
||||
stopwatch.Start();
|
||||
context.FamalyMembers.RemoveRange(famalyMembers);
|
||||
context.SaveChanges();
|
||||
stopwatch.Stop();
|
||||
Console.WriteLine($"Удаление завершено. Времени затрачено: {stopwatch.Elapsed.TotalMilliseconds} мс");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
206
SUBD/Lab_5/Migrations/20230518110637_addIndex.Designer.cs
generated
Normal file
206
SUBD/Lab_5/Migrations/20230518110637_addIndex.Designer.cs
generated
Normal file
@ -0,0 +1,206 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
using SUBD;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Lab_5.Migrations
|
||||
{
|
||||
[DbContext(typeof(Context))]
|
||||
[Migration("20230518110637_addIndex")]
|
||||
partial class addIndex
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "7.0.5")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("SUBD.Models.CategoryExpenses", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("CategorysExpenses");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SUBD.Models.Expens", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("CategoryId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("FamalyMemberId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("MemberId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<decimal>("Summa")
|
||||
.HasColumnType("decimal(10,2)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("CategoryId");
|
||||
|
||||
b.HasIndex("FamalyMemberId");
|
||||
|
||||
b.ToTable("Expenses");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SUBD.Models.FamalyMember", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int?>("MemberId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("MemberId");
|
||||
|
||||
b.HasIndex("Name");
|
||||
|
||||
b.ToTable("FamalyMembers");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SUBD.Models.Income", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("FamalyMemberId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("MemberId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("SourceId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<decimal>("Summa")
|
||||
.HasColumnType("decimal(10,2)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("FamalyMemberId");
|
||||
|
||||
b.HasIndex("SourceId");
|
||||
|
||||
b.ToTable("Incomes");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SUBD.Models.SourceIncome", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("SourcesIncome");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SUBD.Models.Expens", b =>
|
||||
{
|
||||
b.HasOne("SUBD.Models.CategoryExpenses", "CategoryExpenses")
|
||||
.WithMany("Expenses")
|
||||
.HasForeignKey("CategoryId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("SUBD.Models.FamalyMember", "FamalyMember")
|
||||
.WithMany()
|
||||
.HasForeignKey("FamalyMemberId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("CategoryExpenses");
|
||||
|
||||
b.Navigation("FamalyMember");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SUBD.Models.FamalyMember", b =>
|
||||
{
|
||||
b.HasOne("SUBD.Models.FamalyMember", null)
|
||||
.WithMany("Members")
|
||||
.HasForeignKey("MemberId");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SUBD.Models.Income", b =>
|
||||
{
|
||||
b.HasOne("SUBD.Models.FamalyMember", "FamalyMember")
|
||||
.WithMany()
|
||||
.HasForeignKey("FamalyMemberId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("SUBD.Models.SourceIncome", "SourceIncome")
|
||||
.WithMany("Incomes")
|
||||
.HasForeignKey("SourceId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("FamalyMember");
|
||||
|
||||
b.Navigation("SourceIncome");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SUBD.Models.CategoryExpenses", b =>
|
||||
{
|
||||
b.Navigation("Expenses");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SUBD.Models.FamalyMember", b =>
|
||||
{
|
||||
b.Navigation("Members");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SUBD.Models.SourceIncome", b =>
|
||||
{
|
||||
b.Navigation("Incomes");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
27
SUBD/Lab_5/Migrations/20230518110637_addIndex.cs
Normal file
27
SUBD/Lab_5/Migrations/20230518110637_addIndex.cs
Normal file
@ -0,0 +1,27 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Lab_5.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class addIndex : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_FamalyMembers_Name",
|
||||
table: "FamalyMembers",
|
||||
column: "Name");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropIndex(
|
||||
name: "IX_FamalyMembers_Name",
|
||||
table: "FamalyMembers");
|
||||
}
|
||||
}
|
||||
}
|
@ -87,6 +87,8 @@ namespace Lab_5.Migrations
|
||||
|
||||
b.HasIndex("MemberId");
|
||||
|
||||
b.HasIndex("Name");
|
||||
|
||||
b.ToTable("FamalyMembers");
|
||||
});
|
||||
|
||||
|
@ -1,8 +1,10 @@
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace SUBD.Models
|
||||
{
|
||||
[Index(nameof(Name))]
|
||||
public class FamalyMember
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
@ -58,6 +58,18 @@
|
||||
case "12":
|
||||
Controller.DeleteCategoryExpenses();
|
||||
break;
|
||||
case "Добавление":
|
||||
Controller.TestAdd();
|
||||
break;
|
||||
case "Удаление":
|
||||
Controller.TestDelete();
|
||||
break;
|
||||
case "Чтение по айди":
|
||||
Controller.TestReadById();
|
||||
break;
|
||||
case "0":
|
||||
Controller.GetSourcesIncome();
|
||||
break;
|
||||
default:
|
||||
Console.WriteLine("Неверный ввод");
|
||||
break;
|
||||
|
Loading…
Reference in New Issue
Block a user