diff --git a/Infrastructure/EntityTypes/LinkEntityType.cs b/Infrastructure/EntityTypes/LinkEntityType.cs index 237b881..ad688cc 100644 --- a/Infrastructure/EntityTypes/LinkEntityType.cs +++ b/Infrastructure/EntityTypes/LinkEntityType.cs @@ -14,11 +14,14 @@ namespace HN.Infrastructure.EntityTypes builder.Property(o => o.CreatedAt).IsRequired(); builder.HasIndex(o => o.Url).IsUnique(); - builder.HasMany(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(); + }); } } } diff --git a/Infrastructure/EntityTypes/VoteEntityType.cs b/Infrastructure/EntityTypes/VoteEntityType.cs deleted file mode 100644 index e57bf9f..0000000 --- a/Infrastructure/EntityTypes/VoteEntityType.cs +++ /dev/null @@ -1,18 +0,0 @@ -using HN.Domain; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Metadata.Builders; - -namespace HN.Infrastructure.EntityTypes -{ - public sealed class VoteEntityType : IEntityTypeConfiguration - { - public void Configure(EntityTypeBuilder builder) - { - builder.ToTable("link_votes"); - builder.HasKey("LinkId"); - builder.Property(o => o.Type).IsRequired(); - builder.Property(o => o.CreatedAt).IsRequired(); - } - } - -} \ No newline at end of file diff --git a/Infrastructure/LinkRepository.cs b/Infrastructure/LinkRepository.cs index 6eb37c5..87b8614 100644 --- a/Infrastructure/LinkRepository.cs +++ b/Infrastructure/LinkRepository.cs @@ -18,7 +18,7 @@ namespace HN.Infrastructure public Task 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)