add UnitWorkBehavior and some files moving add Docker stuff to prepare heroku deployment rename (Up/Down)vote add sample for msbuild tasks
35 lines
1.1 KiB
C#
35 lines
1.1 KiB
C#
using HN.Domain;
|
|
using HN.Infrastructure.Identity;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
|
|
|
namespace HN.Infrastructure.EntityTypes
|
|
{
|
|
public sealed class CommentEntityType : IEntityTypeConfiguration<Comment>
|
|
{
|
|
public void Configure(EntityTypeBuilder<Comment> builder)
|
|
{
|
|
builder.ToTable("comments");
|
|
builder.HasKey(o => o.Id);
|
|
builder.HasOne<Link>()
|
|
.WithMany()
|
|
.HasForeignKey(o => o.LinkId)
|
|
.IsRequired();
|
|
builder.Property(o => o.Content).IsRequired();
|
|
builder.Property(o => o.CreatedAt).IsRequired();
|
|
|
|
builder.HasOne<User>().WithMany().HasForeignKey(nameof(Comment.CreatedBy)).IsRequired();
|
|
|
|
builder.OwnsMany(o => o.Votes, vote =>
|
|
{
|
|
vote.ToTable("comment_votes");
|
|
vote.WithOwner().HasForeignKey("CommentId");
|
|
vote.HasKey("CommentId", nameof(Comment.CreatedBy));
|
|
vote.HasOne<User>().WithMany().HasForeignKey(nameof(Vote.CreatedBy)).IsRequired();
|
|
vote.Property(o => o.Type).IsRequired();
|
|
vote.Property(o => o.CreatedAt).IsRequired();
|
|
});
|
|
}
|
|
}
|
|
|
|
} |