| | 1 | | using Domain.Entities; |
| | 2 | | using Microsoft.EntityFrameworkCore; |
| | 3 | | using Microsoft.EntityFrameworkCore.Metadata.Builders; |
| | 4 | |
|
| | 5 | | namespace Repository.Mapping; |
| | 6 | | public class CategoriaMap : IEntityTypeConfiguration<Categoria> |
| | 7 | | { |
| | 8 | | public void Configure(EntityTypeBuilder<Categoria> builder) |
| 3 | 9 | | { |
| 3 | 10 | | builder.ToTable(nameof(Categoria)); |
| | 11 | |
|
| 3 | 12 | | builder.Property(c => c.Id) |
| 3 | 13 | | .HasColumnType("varchar(36)") |
| 3 | 14 | | .HasConversion(v => v.ToString(), v => new Guid(v)) |
| 3 | 15 | | .IsRequired(); |
| 3 | 16 | | builder.HasKey(c => c.Id); |
| 3 | 17 | | builder.Property(c => c.Descricao) |
| 3 | 18 | | .IsRequired(false) |
| 3 | 19 | | .HasMaxLength(100); |
| 3 | 20 | | builder.Property(ca => ca.UsuarioId) |
| 3 | 21 | | .HasColumnType("varchar(36)") |
| 3 | 22 | | .HasConversion(v => v.ToString(), v => new Guid(v)) |
| 3 | 23 | | .IsRequired(); |
| 3 | 24 | | builder.Property(ca => ca.TipoCategoriaId) |
| 3 | 25 | | .IsRequired(); |
| | 26 | |
|
| | 27 | |
|
| 3 | 28 | | builder.HasOne(c => c.Usuario) |
| 3 | 29 | | .WithMany(u => u.Categorias) |
| 3 | 30 | | .HasForeignKey(c => c.UsuarioId); |
| | 31 | |
|
| 3 | 32 | | builder.HasOne(c => c.TipoCategoria) |
| 3 | 33 | | .WithMany() |
| 3 | 34 | | .HasForeignKey(c => c.TipoCategoriaId); |
| | 35 | |
|
| 3 | 36 | | } |
| | 37 | | } |