-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFivetContext.cs
62 lines (54 loc) · 1.78 KB
/
FivetContext.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
using System.Reflection;
using Fivet.ZeroIce.model;
using Microsoft.EntityFrameworkCore;
namespace Fivet.Dao
{
public class FivetContext : DbContext
{
public DbSet<Persona> Personas { get; set; }
/// <summary>
/// Configuration
/// </summary>
/// <param name="optionsBuilder"></param>
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlite("Data Source =fivet.db", options =>
{
options.MigrationsAssembly(Assembly.GetExecutingAssembly().FullName);
});
base.OnConfiguring(optionsBuilder);
}
/// <summary>
/// On Model Creating
/// </summary>
/// <param name="modelBuilder"></param>
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Persona>(p =>
{
// Primary Key
p.HasKey(p => p.uid);
// Required rut
p.Property(p => p.rut).IsRequired();
// Email is required
p.Property(p => p.email).IsRequired();
//Email is unique
p.HasIndex(p => p.email).IsUnique();
});
// Insert the data
modelBuilder.Entity<Persona>().HasData(
new Persona()
{
uid = 1,
rut = "190878635",
nombre = "Eduardo",
apellido = "Alvarez",
direccion = "Hola #2908",
telefonoFijo = 3248923,
telefonoMovil = 32479832,
email = "eas010@alumnos.ucn.cl"
}
);
}
}
}