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