-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathContextDB.cs
43 lines (27 loc) · 940 Bytes
/
ContextDB.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
using CursoEntityFramework.Models;
using Microsoft.EntityFrameworkCore;
namespace CursoEntityFramework;
public class ContextDB : DbContext
{
public DbSet<Categories> Categories { get; set; } = null!;
public DbSet<Tasks> Tasks { get; set; } = null!;
public ContextDB(DbContextOptions<ContextDB> options) : base(options) { }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Categories>(categoria =>
{
categoria.ToTable("Categoria");
categoria.HasKey(p => p.Id);
categoria.Property(p => p.Name).IsRequired().HasMaxLength(150);
categoria.Property(p => p.Description);
});
modelBuilder.Entity<Tasks>(tarea =>
{
tarea.ToTable("Tarea");
tarea.HasKey(p => p.Id);
tarea.Property(p => p.Title).IsRequired().HasMaxLength(200);
tarea.Property(p => p.Description);
tarea.Property(p => p.CreatedAt);
});
}
}