-
Notifications
You must be signed in to change notification settings - Fork 0
/
FivetContext.cs
65 lines (61 loc) · 2.02 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
63
64
65
using System.Reflection;
using Fivet.ZeroIce.model;
using Microsoft.EntityFrameworkCore;
namespace Fivet.Dao
{
/// <summary>
/// The Connection to the FivetDataBase
/// </summary>
public class FivetContext: DbContext
{
/// <summary>
/// The Connection to the DataBase
/// </summary>
/// <value></value>
public DbSet<Persona> Personas {get;set;}
public DbSet<Ficha> Fichas {get;set;}
public DbSet<Control> Controles {get;set;}
public DbSet<Foto> Fotos {get;set;}
public DbSet<Examen> Examenes {get;set;}
/// <summary>
/// Configuration
/// </summary>
/// <param name="optionsBuilder"></param>
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
// Using SqlLite.
optionsBuilder.UseSqlite("Data Source = fivet.db",options=>
{
options.MigrationsAssembly(Assembly.GetExecutingAssembly().FullName);
});
base.OnConfiguring(optionsBuilder);
}
/// <summary>
/// Create The ER from Entity.
/// </summary>
/// <param name="modelBuilder"></param>
protected override void OnModelCreating(ModelBuilder modelBuilder)
{ // Update The Model
modelBuilder.Entity<Persona>(p =>
{
// Primary Key
p.HasKey(p=> p.uid);
// Index in Email
p.Property(p=> p.email).IsRequired();
p.HasIndex(p=> p.email).IsUnique();
});
// Insert The Data
modelBuilder.Entity<Persona>().HasData(
new Persona()
{
uid = 1,
nombre ="Martin",
rut ="19.396.034-0",
apellido="Osorio",
direccion="Villa Dulce #6969",
email = "mob010@alumnos.ucn.cl"
}
);
}
}
}