<commit_before>﻿using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity;
using evoART.Models;

namespace evoART.DAL.DbContexts
{
    public class DatabaseContext : DbContext
    {
        public DatabaseContext()
            : base("evoARTConnection")
        {
            Database.SetInitializer(new DatabaseContextInitializer());
        }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            InitializeUserAccountsTable(modelBuilder);
            InitializeAccountValidationsTable(modelBuilder);
            InitializeRolesTable(modelBuilder);
            InitializeSessionsTable(modelBuilder);
        }

        protected virtual void InitializeUserAccountsTable(DbModelBuilder modelBuilder)
        {
            modelBuilder.Entity<AccountModels.UserAccount>()
                .HasKey(t => t.UserId)
                .Property(t => t.UserId).HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);<commit_msg>Made the database context a singleton<commit_after>﻿using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity;
using evoART.Models;

namespace evoART.DAL.DbContexts
{
    /// <summary>
    /// This class is a singleton
    /// </summary>
    public class DatabaseContext : DbContext
    {
        private static DatabaseContext _dbContext = null;

        /// <summary>
        /// Get an instance of the DatabaseContext class
        /// </summary>
        public static DatabaseContext DatabaseContextInstance
        {
            get
            {
                return _dbContext ?? (_dbContext = new DatabaseContext());
            }
        }

        private DatabaseContext()
            : base("evoARTConnection")
        {
            Database.SetInitializer(new DatabaseContextInitializer());
        }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            InitializeUserAccountsTable(modelBuilder);
            InitializeAccountValidationsTable(modelBuilder);
            InitializeRolesTable(modelBuilder);
            InitializeSessionsTable(modelBuilder);
        }

        protected virtual void InitializeUserAccountsTable(DbModelBuilder modelBuilder)
        {
            modelBuilder.Entity<AccountModels.UserAccount>()
                .HasKey(t => t.UserId)
                .Property(t => t.UserId).HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
{'fraction_non_alphanumeric': 0.07872078720787208, 'fraction_numerical': 0.0, 'mean_word_length': 2.4857142857142858, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3419848', 'n_tokens_mistral': 576, 'n_tokens_neox': 569, 'n_words': 107}