Fix database schema

This commit is contained in:
Stanislav Mykhailenko 2023-05-14 19:54:40 +03:00
parent 0d47f075db
commit c01b6e8c77
GPG key ID: 1E95E66A9C9D6A36
6 changed files with 50 additions and 8 deletions

View file

@ -6,6 +6,6 @@
public virtual ICollection<User>? Users { get; set; } = new HashSet<User>();
public virtual ICollection<Card>? Cards { get; set; } = new HashSet<Card>();
public virtual ICollection<Column>? Columns { get; set; } = new HashSet<Column>();
}
}

View file

@ -4,12 +4,11 @@
{
public string Name { get; set; }
public string Description { get; set; }
public string Column { get; set; }
public int SenderId { get; set; }
public int BoardId { get; set; }
public int ColumnId { get; set; }
public virtual User Sender { get; set; }
public virtual Board Board { get; set; }
public virtual Column Column { get; set; }
public virtual ICollection<Comment> Comments { get; set; } = new HashSet<Comment>();
}

12
Entities/Column.cs Normal file
View file

@ -0,0 +1,12 @@
namespace NG_2023_Kanban.Entities
{
public class Column : BaseEntity
{
public string Name { get; set; }
public int BoardId { get; set; }
public virtual Board Board { get; set; }
public virtual ICollection<Card>? Cards { get; set; } = new HashSet<Card>();
}
}

View file

@ -10,6 +10,7 @@
public bool IsAdmin { get; set; }
public virtual ICollection<Board>? Boards { get; set; } = new HashSet<Board>();
public virtual ICollection<Card>? Cards { get; set; } = new HashSet<Card>();
public virtual ICollection<Comment>? Comments { get; set; } = new HashSet<Comment>();
}
}

View file

@ -17,13 +17,16 @@ namespace NG_2023_Kanban.EntityConfiguration
builder.Property(x => x.Description).IsRequired();
builder.Property(x => x.Description).HasMaxLength(100);
builder.Property(x => x.Column).IsRequired();
builder.Property(x => x.Column).HasMaxLength(100);
builder
.HasOne(x => x.Sender)
.WithMany(x => x.Cards)
.HasForeignKey(x => x.SenderId)
.HasPrincipalKey(x => x.Id);
builder
.HasOne(x => x.Board)
.HasOne(x => x.Column)
.WithMany(x => x.Cards)
.HasForeignKey(x => x.BoardId)
.HasForeignKey(x => x.ColumnId)
.HasPrincipalKey(x => x.Id);
}
}

View file

@ -0,0 +1,27 @@
using NG_2023_Kanban.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace NG_2023_Kanban.EntityConfiguration
{
public class ColumnConfiguration : IEntityTypeConfiguration<Column>
{
public void Configure(EntityTypeBuilder<Column> builder)
{
builder.HasIndex(x => x.Id);
builder.Property(x => x.Id).IsRequired();
builder.Property(x => x.Name).IsRequired();
builder.Property(x => x.Name).HasMaxLength(100);
builder.Property(x => x.Board).IsRequired();
builder.Property(x => x.Board).HasMaxLength(100);
builder
.HasOne(x => x.Board)
.WithMany(x => x.Columns)
.HasForeignKey(x => x.BoardId)
.HasPrincipalKey(x => x.Id);
}
}
}