Skip to content

Commit

Permalink
feat: Aplica mapeamento inicial do modelo de usuários
Browse files Browse the repository at this point in the history
  • Loading branch information
renebentes committed Oct 21, 2022
1 parent 2de4478 commit 7e25787
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions Blog/Data/Mappings/UserMap.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using Blog.Models;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace Blog.Data.Mappings;

public class UserMap : IEntityTypeConfiguration<User>
{
public void Configure(EntityTypeBuilder<User> builder)
{
builder.ToTable(nameof(User));

builder.HasKey(u => u.Id);

builder.Property(u => u.Id)
.ValueGeneratedOnAdd()
.UseIdentityColumn();

builder.Property(u => u.Name)
.IsRequired()
.HasColumnType("NVARCHAR")
.HasMaxLength(80);

builder.Property(u => u.Email)
.IsRequired()
.HasColumnType("VARCHAR")
.HasMaxLength(200);

builder.Property(u => u.PasswordHash)
.IsRequired()
.HasColumnType("VARCHAR")
.HasMaxLength(255);

builder.Property(u => u.Bio)
.IsRequired()
.HasColumnType("TEXT");

builder.Property(u => u.Image)
.IsRequired()
.HasColumnType("VARCHAR")
.HasMaxLength(2000);

builder.Property(u => u.Slug)
.IsRequired()
.HasColumnType("VARCHAR")
.HasMaxLength(80);

builder.HasIndex(u => u.Slug, "IX_User_Slug")
.IsUnique();
}
}

0 comments on commit 7e25787

Please sign in to comment.