comment-a-link #24
@ -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();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -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)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user