aboutsummaryrefslogtreecommitdiff
path: root/src/DevHive.Data/DevHiveContext.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/DevHive.Data/DevHiveContext.cs')
-rw-r--r--src/DevHive.Data/DevHiveContext.cs35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/DevHive.Data/DevHiveContext.cs b/src/DevHive.Data/DevHiveContext.cs
new file mode 100644
index 0000000..e8eb5fb
--- /dev/null
+++ b/src/DevHive.Data/DevHiveContext.cs
@@ -0,0 +1,35 @@
+using System;
+using DevHive.Data.Models;
+using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
+using Microsoft.EntityFrameworkCore;
+
+namespace DevHive.Data
+{
+ public class DevHiveContext : IdentityDbContext<User, Role, Guid>
+ {
+ public DevHiveContext(DbContextOptions options)
+ : base(options) { }
+
+ public DbSet<Technology> Technologies { get; set; }
+ public DbSet<Language> Languages { get; set; }
+
+ protected override void OnModelCreating(ModelBuilder builder)
+ {
+ builder.Entity<User>()
+ .HasIndex(x => x.UserName)
+ .IsUnique();
+
+ builder.Entity<User>()
+ .HasMany(x => x.Roles);
+
+ builder.Entity<User>()
+ .HasMany(x => x.Friends);
+
+ builder.Entity<Role>()
+ .HasIndex(x => x.Id)
+ .IsUnique();
+
+ base.OnModelCreating(builder);
+ }
+ }
+}