ENEI2019-Public/api/Data/DataContext.cs

56 lines
1.5 KiB
C#
Raw Permalink Normal View History

2018-12-12 15:17:08 +00:00
using api.Models;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
namespace api.Data
{
2019-02-26 01:52:05 +00:00
public class DataContext : IdentityDbContext<User,Role,int,IdentityUserClaim<int>,UserRole,IdentityUserLogin<int>,
IdentityRoleClaim<int>,IdentityUserToken<int>>
2018-12-12 15:17:08 +00:00
{
public DataContext(DbContextOptions<DataContext> options):base(options) { }
public DbSet<Value> Values{get;set;}
public DbSet<Photo> Photos {get;set;}
2019-02-24 02:16:08 +00:00
public DbSet<Team> Teams {get;set;}
2018-12-12 15:17:08 +00:00
2019-02-24 02:16:08 +00:00
public DbSet<Event> Events {get;set;}
public DbSet<EventLoc> EventLocs {get;set;}
public DbSet<EventLocVisited> EventLocsVisited {get;set;}
2019-03-14 18:10:59 +00:00
public DbSet<Cromos> Cromos {get;set;}
2019-02-24 02:16:08 +00:00
public DbSet<Log>Logs{get;set;}
2019-02-26 01:52:05 +00:00
public DbSet<Product>Products{get;set;}
2018-12-12 15:17:08 +00:00
2019-02-26 01:52:05 +00:00
protected override void OnModelCreating(ModelBuilder builder)
{
base.OnModelCreating(builder);
2018-12-12 15:17:08 +00:00
2019-02-26 01:52:05 +00:00
//para o ef saber as relações
builder.Entity<UserRole>(userRole =>
{
userRole.HasKey(ur=> new {ur.UserId, ur.RoleId});
2018-12-12 15:17:08 +00:00
2019-02-26 01:52:05 +00:00
userRole.HasOne( ur=>ur.Role)
.WithMany(r=>r.UserRoles)
.HasForeignKey(ur=> ur.RoleId)
.IsRequired();
2018-12-12 15:17:08 +00:00
2019-02-26 01:52:05 +00:00
userRole.HasOne( ur=>ur.User)
.WithMany(r=>r.UserRoles)
.HasForeignKey(ur=> ur.UserId)
.IsRequired();
});
}
2018-12-12 15:17:08 +00:00
}
}