Успешно создана миграция и подключена база данных

This commit is contained in:
Kirill 2024-04-30 22:59:25 +04:00
parent 609cc81c7a
commit 5cec4e59ac
12 changed files with 731 additions and 24 deletions

View File

@ -7,11 +7,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SchoolApp", "SchoolApp\Scho
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SchoolDataModels", "SchoolsDataModels\SchoolDataModels.csproj", "{ADBB4992-BE2F-4B10-83CC-335E5B92EA35}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SchoolContracts", "SchoolContracts\SchoolContracts.csproj", "{D58B0AFE-E28D-4583-B9F1-C0EDF443243F}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SchoolContracts", "SchoolContracts\SchoolContracts.csproj", "{D58B0AFE-E28D-4583-B9F1-C0EDF443243F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SchoolBusinessLogic", "SchoolBusinessLogic\SchoolBusinessLogic.csproj", "{E78D42A3-7FA0-4E3A-B0C8-AEC70B3EE331}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SchoolBusinessLogic", "SchoolBusinessLogic\SchoolBusinessLogic.csproj", "{E78D42A3-7FA0-4E3A-B0C8-AEC70B3EE331}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SchoolDatabaseImplement", "SchoolDatabaseImplement\SchoolDatabaseImplement.csproj", "{8C8F56D4-E267-498F-AFCD-06701962D09F}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SchoolDatabaseImplement", "SchoolDatabaseImplement\SchoolDatabaseImplement.csproj", "{8C8F56D4-E267-498F-AFCD-06701962D09F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution

View File

@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
@ -13,4 +13,11 @@
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SchoolBusinessLogic\SchoolBusinessLogic.csproj" />
<ProjectReference Include="..\SchoolContracts\SchoolContracts.csproj" />
<ProjectReference Include="..\SchoolDatabaseImplement\SchoolDatabaseImplement.csproj" />
<ProjectReference Include="..\SchoolsDataModels\SchoolDataModels.csproj" />
</ItemGroup>
</Project>

View File

@ -13,7 +13,7 @@ namespace SchoolContracts.BindingModels
public string Name { get; set; } = string.Empty;
public string Direction { get; set; } = string.Empty;
public string Description { get; set; } = string.Empty;
public Dictionary<int, (ILessonModel, int)> InterestLessons
public Dictionary<int, ILessonModel> InterestLessons
{
get;
set;

View File

@ -17,7 +17,7 @@ namespace SchoolContracts.ViewModels
public string Direction { get; set; } = string.Empty;
[DisplayName("Описание интереса")]
public string Description { get; set; } = string.Empty;
public Dictionary<int, (ILessonModel, int)> InterestLessons
public Dictionary<int, ILessonModel> InterestLessons
{
get;
set;

View File

@ -0,0 +1,234 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using SchoolDatabaseImplement;
#nullable disable
namespace SchoolDatabaseImplement.Migrations
{
[DbContext(typeof(SchoolDatabase))]
[Migration("20240430184208_InitialCreate")]
partial class InitialCreate
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "7.0.0")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
modelBuilder.Entity("SchoolDatabaseImplement.Models.Achievement", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int?>("AchievementId")
.HasColumnType("int");
b.Property<string>("Description")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int>("LessonId")
.HasColumnType("int");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<DateTime>("ReceiptDate")
.HasColumnType("datetime2");
b.HasKey("Id");
b.HasIndex("AchievementId");
b.ToTable("Achievements");
});
modelBuilder.Entity("SchoolDatabaseImplement.Models.Interest", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Description")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Direction")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Interests");
});
modelBuilder.Entity("SchoolDatabaseImplement.Models.InterestLesson", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("InterestId")
.HasColumnType("int");
b.Property<int>("LessonId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("InterestId");
b.HasIndex("LessonId");
b.ToTable("InterestLessons");
});
modelBuilder.Entity("SchoolDatabaseImplement.Models.Lesson", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<DateTime>("TimeEnd")
.HasColumnType("datetime2");
b.Property<DateTime>("TimeStart")
.HasColumnType("datetime2");
b.Property<int>("UserId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("Lessons");
});
modelBuilder.Entity("SchoolDatabaseImplement.Models.User", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<DateTime>("BirthDate")
.HasColumnType("datetime2");
b.Property<string>("Mail")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("PhoneNumber")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int?>("UserId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("Users");
});
modelBuilder.Entity("SchoolDatabaseImplement.Models.Achievement", b =>
{
b.HasOne("SchoolDatabaseImplement.Models.Lesson", "Lesson")
.WithMany("Achievements")
.HasForeignKey("AchievementId");
b.Navigation("Lesson");
});
modelBuilder.Entity("SchoolDatabaseImplement.Models.InterestLesson", b =>
{
b.HasOne("SchoolDatabaseImplement.Models.Interest", "Interest")
.WithMany("Lessons")
.HasForeignKey("InterestId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("SchoolDatabaseImplement.Models.Lesson", "Lesson")
.WithMany("InterestLessons")
.HasForeignKey("LessonId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Interest");
b.Navigation("Lesson");
});
modelBuilder.Entity("SchoolDatabaseImplement.Models.Lesson", b =>
{
b.HasOne("SchoolDatabaseImplement.Models.User", "User")
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("User");
});
modelBuilder.Entity("SchoolDatabaseImplement.Models.User", b =>
{
b.HasOne("SchoolDatabaseImplement.Models.User", null)
.WithMany("Users")
.HasForeignKey("UserId");
});
modelBuilder.Entity("SchoolDatabaseImplement.Models.Interest", b =>
{
b.Navigation("Lessons");
});
modelBuilder.Entity("SchoolDatabaseImplement.Models.Lesson", b =>
{
b.Navigation("Achievements");
b.Navigation("InterestLessons");
});
modelBuilder.Entity("SchoolDatabaseImplement.Models.User", b =>
{
b.Navigation("Users");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,166 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace SchoolDatabaseImplement.Migrations
{
/// <inheritdoc />
public partial class InitialCreate : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Interests",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Name = table.Column<string>(type: "nvarchar(max)", nullable: false),
Direction = table.Column<string>(type: "nvarchar(max)", nullable: false),
Description = table.Column<string>(type: "nvarchar(max)", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Interests", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Users",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Name = table.Column<string>(type: "nvarchar(max)", nullable: false),
BirthDate = table.Column<DateTime>(type: "datetime2", nullable: false),
Mail = table.Column<string>(type: "nvarchar(max)", nullable: false),
PhoneNumber = table.Column<string>(type: "nvarchar(max)", nullable: false),
Password = table.Column<string>(type: "nvarchar(max)", nullable: false),
UserId = table.Column<int>(type: "int", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Users", x => x.Id);
table.ForeignKey(
name: "FK_Users_Users_UserId",
column: x => x.UserId,
principalTable: "Users",
principalColumn: "Id");
});
migrationBuilder.CreateTable(
name: "Lessons",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
TimeStart = table.Column<DateTime>(type: "datetime2", nullable: false),
TimeEnd = table.Column<DateTime>(type: "datetime2", nullable: false),
UserId = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Lessons", x => x.Id);
table.ForeignKey(
name: "FK_Lessons_Users_UserId",
column: x => x.UserId,
principalTable: "Users",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Achievements",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
LessonId = table.Column<int>(type: "int", nullable: false),
AchievementId = table.Column<int>(type: "int", nullable: true),
Name = table.Column<string>(type: "nvarchar(max)", nullable: false),
Description = table.Column<string>(type: "nvarchar(max)", nullable: false),
ReceiptDate = table.Column<DateTime>(type: "datetime2", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Achievements", x => x.Id);
table.ForeignKey(
name: "FK_Achievements_Lessons_AchievementId",
column: x => x.AchievementId,
principalTable: "Lessons",
principalColumn: "Id");
});
migrationBuilder.CreateTable(
name: "InterestLessons",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
InterestId = table.Column<int>(type: "int", nullable: false),
LessonId = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_InterestLessons", x => x.Id);
table.ForeignKey(
name: "FK_InterestLessons_Interests_InterestId",
column: x => x.InterestId,
principalTable: "Interests",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_InterestLessons_Lessons_LessonId",
column: x => x.LessonId,
principalTable: "Lessons",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_Achievements_AchievementId",
table: "Achievements",
column: "AchievementId");
migrationBuilder.CreateIndex(
name: "IX_InterestLessons_InterestId",
table: "InterestLessons",
column: "InterestId");
migrationBuilder.CreateIndex(
name: "IX_InterestLessons_LessonId",
table: "InterestLessons",
column: "LessonId");
migrationBuilder.CreateIndex(
name: "IX_Lessons_UserId",
table: "Lessons",
column: "UserId");
migrationBuilder.CreateIndex(
name: "IX_Users_UserId",
table: "Users",
column: "UserId");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Achievements");
migrationBuilder.DropTable(
name: "InterestLessons");
migrationBuilder.DropTable(
name: "Interests");
migrationBuilder.DropTable(
name: "Lessons");
migrationBuilder.DropTable(
name: "Users");
}
}
}

View File

@ -0,0 +1,231 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using SchoolDatabaseImplement;
#nullable disable
namespace SchoolDatabaseImplement.Migrations
{
[DbContext(typeof(SchoolDatabase))]
partial class SchoolDatabaseModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "7.0.0")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
modelBuilder.Entity("SchoolDatabaseImplement.Models.Achievement", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int?>("AchievementId")
.HasColumnType("int");
b.Property<string>("Description")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int>("LessonId")
.HasColumnType("int");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<DateTime>("ReceiptDate")
.HasColumnType("datetime2");
b.HasKey("Id");
b.HasIndex("AchievementId");
b.ToTable("Achievements");
});
modelBuilder.Entity("SchoolDatabaseImplement.Models.Interest", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Description")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Direction")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Interests");
});
modelBuilder.Entity("SchoolDatabaseImplement.Models.InterestLesson", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("InterestId")
.HasColumnType("int");
b.Property<int>("LessonId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("InterestId");
b.HasIndex("LessonId");
b.ToTable("InterestLessons");
});
modelBuilder.Entity("SchoolDatabaseImplement.Models.Lesson", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<DateTime>("TimeEnd")
.HasColumnType("datetime2");
b.Property<DateTime>("TimeStart")
.HasColumnType("datetime2");
b.Property<int>("UserId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("Lessons");
});
modelBuilder.Entity("SchoolDatabaseImplement.Models.User", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<DateTime>("BirthDate")
.HasColumnType("datetime2");
b.Property<string>("Mail")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("PhoneNumber")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int?>("UserId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("Users");
});
modelBuilder.Entity("SchoolDatabaseImplement.Models.Achievement", b =>
{
b.HasOne("SchoolDatabaseImplement.Models.Lesson", "Lesson")
.WithMany("Achievements")
.HasForeignKey("AchievementId");
b.Navigation("Lesson");
});
modelBuilder.Entity("SchoolDatabaseImplement.Models.InterestLesson", b =>
{
b.HasOne("SchoolDatabaseImplement.Models.Interest", "Interest")
.WithMany("Lessons")
.HasForeignKey("InterestId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("SchoolDatabaseImplement.Models.Lesson", "Lesson")
.WithMany("InterestLessons")
.HasForeignKey("LessonId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Interest");
b.Navigation("Lesson");
});
modelBuilder.Entity("SchoolDatabaseImplement.Models.Lesson", b =>
{
b.HasOne("SchoolDatabaseImplement.Models.User", "User")
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("User");
});
modelBuilder.Entity("SchoolDatabaseImplement.Models.User", b =>
{
b.HasOne("SchoolDatabaseImplement.Models.User", null)
.WithMany("Users")
.HasForeignKey("UserId");
});
modelBuilder.Entity("SchoolDatabaseImplement.Models.Interest", b =>
{
b.Navigation("Lessons");
});
modelBuilder.Entity("SchoolDatabaseImplement.Models.Lesson", b =>
{
b.Navigation("Achievements");
b.Navigation("InterestLessons");
});
modelBuilder.Entity("SchoolDatabaseImplement.Models.User", b =>
{
b.Navigation("Users");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -13,39 +13,45 @@ namespace SchoolDatabaseImplement.Models
{
public class Interest : IInterestModel
{
public int Id { get; private set; }
public int Id { get; set; }
[Required]
public string Name { get; private set; } = string.Empty;
[Required]
public string Direction { get; private set; } = string.Empty;
public string Description { get; private set; } = string.Empty;
[ForeignKey("InterestId")]
public virtual List<InterestLesson> InterestLessons { get; set; } = new();
[Required]
Dictionary<int, (ILessonModel, int)> IInterestModel.InterestLessons => throw new NotImplementedException();
public static Interest? Create(InterestBindingModel model)
private Dictionary<int, ILessonModel>? _InterestLessons = null;
[NotMapped]
public Dictionary<int, ILessonModel> InterestLessons
{
if (model == null)
get
{
return null;
if (_InterestLessons == null)
{
_InterestLessons = Lessons.ToDictionary(recPC => recPC.LessonId, recPC => recPC.Lesson as ILessonModel);
}
return _InterestLessons;
}
}
[ForeignKey("InterestId")]
public virtual List<InterestLesson> Lessons { get; set; } = new();
public static Interest Create(SchoolDatabase context, InterestBindingModel model)
{
return new Interest()
{
Id = model.Id,
Name = model.Name,
Direction = model.Direction,
Description = model.Description
Description = model.Description,
Lessons = model.InterestLessons.Select(x => new InterestLesson
{
Lesson = context.Lessons.First(y => y.Id == x.Key)
}).ToList()
};
}
public void Update(InterestBindingModel model)
{
if (model == null)
{
return;
}
Name = model.Name;
Direction = model.Direction;
Description = model.Description;
@ -55,9 +61,36 @@ namespace SchoolDatabaseImplement.Models
Id = Id,
Name = Name,
Direction = Direction,
Description = Description
Description = Description,
InterestLessons = InterestLessons
};
public void UpdateLessons(SchoolDatabase context,
InterestBindingModel model)
{
var InterestLessons = context.InterestLessons.Where(rec => rec.InterestId == model.Id).ToList();
if (InterestLessons != null)
{ // удалили те, которых нет в модели
context.InterestLessons.RemoveRange(InterestLessons.Where(rec
=> !model.InterestLessons.ContainsKey(rec.LessonId)));
context.SaveChanges();
// обновили количество у существующих записей
foreach (var updateLesson in InterestLessons)
{
model.InterestLessons.Remove(updateLesson.LessonId);
}
context.SaveChanges();
}
var Interest = context.Interests.First(x => x.Id == Id);
foreach (var pc in model.InterestLessons)
{
context.InterestLessons.Add(new InterestLesson
{
Interest = Interest,
Lesson = context.Lessons.First(x => x.Id == pc.Key),
});
context.SaveChanges();
}
_InterestLessons = null;
}
}
}

View File

@ -23,6 +23,9 @@ namespace SchoolDatabaseImplement.Models
[Required]
public int UserId { get; private set; }
public virtual User? User { get; private set; }
[ForeignKey("AchievementId")]
public virtual List<Achievement> Achievements { get; set; } = new();
public static Lesson? Create(LessonBindingModel model)
{
if (model == null)

View File

@ -24,6 +24,9 @@ namespace SchoolDatabaseImplement.Models
public string PhoneNumber { get; private set; } = string.Empty;
public string Password { get; private set; } = string.Empty;
[ForeignKey("UserId")]
public virtual List<User> Users { get; set; } = new();
public static User? Create(UserBindingModel model)
{
if (model == null)

View File

@ -0,0 +1,30 @@
using Microsoft.EntityFrameworkCore;
using SchoolDatabaseImplement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SchoolDatabaseImplement
{
public class SchoolDatabase : DbContext
{
protected override void OnConfiguring(DbContextOptionsBuilder
optionsBuilder)
{
if (optionsBuilder.IsConfigured == false)
{
optionsBuilder.UseSqlServer(@"Data Source=firsovpk;Initial Catalog=SchoolDataBase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"
);
}
base.OnConfiguring(optionsBuilder);
}
public virtual DbSet<User> Users { set; get; }
public virtual DbSet<Lesson> Lessons { set; get; }
public virtual DbSet<InterestLesson> InterestLessons { set; get; }
public virtual DbSet<Interest> Interests { set; get; }
public virtual DbSet<Achievement> Achievements { set; get; }
}
}

View File

@ -14,6 +14,6 @@ namespace SchoolDataModels.Models
string Description { get; }
Dictionary<int, (ILessonModel, int)> InterestLessons { get; }
Dictionary<int, ILessonModel> InterestLessons { get; }
}
}