comment-a-link #24
@ -14,11 +14,14 @@ namespace HN.Infrastructure.EntityTypes
|
|||||||
builder.Property(o => o.CreatedAt).IsRequired();
|
builder.Property(o => o.CreatedAt).IsRequired();
|
||||||
builder.HasIndex(o => o.Url).IsUnique();
|
builder.HasIndex(o => o.Url).IsUnique();
|
||||||
|
|
||||||
builder.HasMany<Vote>(o => o.Votes)
|
builder.OwnsMany(o => o.Votes, vote =>
|
||||||
.WithOne()
|
{
|
||||||
.HasForeignKey("LinkId")
|
vote.ToTable("link_votes");
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
vote.WithOwner().HasForeignKey("LinkId");
|
||||||
.IsRequired();
|
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)
|
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)
|
public Task UpdateAsync(Link link)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user