31 lines
1.1 KiB
C#
31 lines
1.1 KiB
C#
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
|
using PnvPanel.Domain.Nodes;
|
|
|
|
namespace PnvPanel.Infrastructure.Persistence.Configurations;
|
|
|
|
public class NodeConfiguration : IEntityTypeConfiguration<Node>
|
|
{
|
|
public void Configure(EntityTypeBuilder<Node> builder)
|
|
{
|
|
builder.ToTable("Nodes");
|
|
builder.HasKey(x => x.Id);
|
|
|
|
builder.Property(x => x.Name).IsRequired().HasMaxLength(100);
|
|
|
|
builder.Property(x => x.BaseAddress)
|
|
.IsRequired()
|
|
.HasMaxLength(500)
|
|
.HasConversion(uri => uri.ToString(), s => new Uri(s, UriKind.Absolute));
|
|
|
|
builder.Property(x => x.Location).HasMaxLength(100);
|
|
builder.Property(x => x.Status).HasConversion<string>().HasMaxLength(32);
|
|
|
|
builder.OwnsOne(x => x.Credentials, credentials =>
|
|
{
|
|
credentials.Property(c => c.Username).HasColumnName("CredentialsUsername").IsRequired().HasMaxLength(200);
|
|
credentials.Property(c => c.ProtectedPassword).HasColumnName("CredentialsProtectedPassword").IsRequired();
|
|
});
|
|
}
|
|
}
|