This commit is contained in:
Dmitrii Kollerov
2026-09-25 08:05:46 +03:00
parent 2b05c26eb3
commit 68da43a673
29 changed files with 867 additions and 2 deletions
+36
View File
@@ -0,0 +1,36 @@
using example_csharp_app.Dto;
using Microsoft.EntityFrameworkCore;
using System;
namespace example_app.Database.Connector;
public class AppDbContext(DbContextOptions<AppDbContext> options) : DbContext(options)
{
public DbSet<BookDto> Books { set; get; }
protected override void OnModelCreating(ModelBuilder builder)
{
base.OnModelCreating(builder);
builder.Entity<BookDto>()
.ToTable("Books")
.HasKey(x => x.Id);
builder.Entity<BookDto>()
.Property(x => x.Author)
.IsRequired();
builder.Entity<BookDto>()
.Property(x => x.Title)
.IsRequired();
builder.Entity<BookDto>()
.Property(x => x.YearPublished)
.IsRequired();
builder.Entity<BookDto>()
.Property(x => x.BookIndex)
.IsRequired();
builder.Entity<BookDto>()
.Property(x => x.BookIndex)
.HasColumnType("xml");
}
}