comment-a-link #24

Merged
jleicher merged 3 commits from comment-a-link into master 2020-12-11 09:46:43 +01:00
3 changed files with 9 additions and 24 deletions
Showing only changes of commit 39a2523381 - Show all commits

View File

@ -14,11 +14,14 @@ namespace HN.Infrastructure.EntityTypes
builder.Property(o => o.CreatedAt).IsRequired();
builder.HasIndex(o => o.Url).IsUnique();
builder.HasMany<Vote>(o => o.Votes)
.WithOne()
.HasForeignKey("LinkId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
builder.OwnsMany(o => o.Votes, vote =>
{
vote.ToTable("link_votes");
vote.WithOwner().HasForeignKey("LinkId");
vote.HasKey("LinkId");
vote.Property(o => o.Type).IsRequired();
vote.Property(o => o.CreatedAt).IsRequired();
});
}
}
}

View File

@ -1,18 +0,0 @@
using HN.Domain;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace HN.Infrastructure.EntityTypes
{
public sealed class VoteEntityType : IEntityTypeConfiguration<Vote>
{
public void Configure(EntityTypeBuilder<Vote> builder)
{
builder.ToTable("link_votes");
builder.HasKey("LinkId");
builder.Property(o => o.Type).IsRequired();
builder.Property(o => o.CreatedAt).IsRequired();
}
}
}

View File

@ -18,7 +18,7 @@ namespace HN.Infrastructure
public Task<Link> GetByIdAsync(Guid id)
{
return Entries.Include(l => l.Votes).SingleOrDefaultAsync(o => o.Id == id);
return Entries.SingleOrDefaultAsync(o => o.Id == id);
}
public Task UpdateAsync(Link link)