<commit_before>﻿// -----------------------------------------------------------------------
// <copyright file="MyDBContext.cs" company="">
// Copyright 2013 <NAME>
// </copyright>
// -----------------------------------------------------------------------

using System.Data.Entity;
using EntityData.Migrations;
using QDMS;

namespace EntityData
{
    public partial class MyDBContext : DbContext
    {
        public MyDBContext()
            : base("Name=qdmsEntities")
        {
        }

        public MyDBContext(string connectionString)
        {
            Database.Connection.ConnectionString = connectionString;
        }

        public DbSet<Instrument> Instruments { get; set; }
        public DbSet<Tag> Tags { get; set; }
        public DbSet<Exchange> Exchanges { get; set; }
        public DbSet<Datasource> Datasources { get; set; }
        public DbSet<SessionTemplate> SessionTemplates { get; set; }
        public DbSet<ExchangeSession> ExchangeSessions { get; set; }
        public DbSet<InstrumentSession> InstrumentSessions { get; set; }
        public DbSet<TemplateSession> TemplateSessions { get; set; }
        public DbSet<UnderlyingSymbol> UnderlyingSymbols { get; set; }
        public DbSet<ContinuousFuture> ContinuousFutures { get; set; }
        public DbSet<DataUpdateJobDetails> DataUpdateJobs { get; set; }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Configurations.Add(new InstrumentConfig());
            modelBuilder.Configurations.Add(new TagConfig());
            modelBuilder.Configurations.Add(new ExchangeConfig());
            modelBuilder.Configurations.Add(new DatasourceConfig());
            modelBuilder.Configurations.Add(new UnderlyingSymbolConfig());
            modelBuilder.Configurations.Add(new ContinuousFutureConfig());
            modelBuilder.Configurations.Add(new DataUpdateJobConfig());

            modelBuilder.Entity<ExchangeSession>().ToTable("exchangesessions");
            modelBuilder.Entity<InstrumentSession>().ToTable("instrumentsessions");
            modelBuilder.Entity<TemplateSession>().ToTable("templatesessions");

            modelBuilder.Entity<Instrument>()
            .HasMany(c => c.Tags)
            .WithMany()             
            .Map(x =>
            {
                x.MapLeftKey("InstrumentID");
                x.MapRightKey("TagID");
                x.ToTable("tag_map");
            });


            modelBuilder.Entity<Instrument>().Property(x => x.Strike).HasPrecision(16, 8);
            modelBuilder.Entity<Instrument>().Property(x => x.MinTick).HasPrecision(16, 8);

            modelBuilder.Entity<ExchangeSession>().Property(x => x.OpeningTime).HasPrecision(0);
            modelBuilder.Entity<ExchangeSession>().Property(x => x.ClosingTime).HasPrecision(0);

            modelBuilder.Entity<InstrumentSession>().Property(x => x.OpeningTime).HasPrecision(0);
            modelBuilder.Entity<InstrumentSession>().Property(x => x.ClosingTime).HasPrecision(0);

            modelBuilder.Entity<TemplateSession>().Property(x => x.OpeningTime).HasPrecision(0);
            modelBuilder.Entity<TemplateSession>().Property(x => x.ClosingTime).HasPrecision(0);

            
            Database.SetInitializer(new MigrateDatabaseToLatestVersion<MyDBContext, MyDbContextConfiguration>());
        }
    }
}<commit_msg>Add the new index to MyDBContext<commit_after>﻿// -----------------------------------------------------------------------
// <copyright file="MyDBContext.cs" company="">
// Copyright 2013 <NAME>
// </copyright>
// -----------------------------------------------------------------------

using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity;
using System.Data.Entity.Infrastructure.Annotations;
using EntityData.Migrations;
using QDMS;

namespace EntityData
{
    public partial class MyDBContext : DbContext
    {
        public MyDBContext()
            : base("Name=qdmsEntities")
        {
        }

        public MyDBContext(string connectionString)
        {
            Database.Connection.ConnectionString = connectionString;
        }

        public DbSet<Instrument> Instruments { get; set; }
        public DbSet<Tag> Tags { get; set; }
        public DbSet<Exchange> Exchanges { get; set; }
        public DbSet<Datasource> Datasources { get; set; }
        public DbSet<SessionTemplate> SessionTemplates { get; set; }
        public DbSet<ExchangeSession> ExchangeSessions { get; set; }
        public DbSet<InstrumentSession> InstrumentSessions { get; set; }
        public DbSet<TemplateSession> TemplateSessions { get; set; }
        public DbSet<UnderlyingSymbol> UnderlyingSymbols { get; set; }
        public DbSet<ContinuousFuture> ContinuousFutures { get; set; }
        public DbSet<DataUpdateJobDetails> DataUpdateJobs { get; set; }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Configurations.Add(new InstrumentConfig());
            modelBuilder.Configurations.Add(new TagConfig());
            modelBuilder.Configurations.Add(new ExchangeConfig());
            modelBuilder.Configurations.Add(new DatasourceConfig());
            modelBuilder.Configurations.Add(new UnderlyingSymbolConfig());
            modelBuilder.Configurations.Add(new ContinuousFutureConfig());
            modelBuilder.Configurations.Add(new DataUpdateJobConfig());

            modelBuilder.Entity<ExchangeSession>().ToTable("exchangesessions");
            modelBuilder.Entity<InstrumentSession>().ToTable("instrumentsessions");
            modelBuilder.Entity<TemplateSession>().ToTable("templatesessions");

            modelBuilder.Entity<Instrument>()
            .HasMany(c => c.Tags)
            .WithMany()             
            .Map(x =>
            {
                x.MapLeftKey("InstrumentID");
                x.MapRightKey("TagID");
                x.ToTable("tag_map");
            });


            modelBuilder.Entity<Instrument>().Property(x => x.Strike).HasPrecision(16, 8);
            modelBuilder.Entity<Instrument>().Property(x => x.MinTick).HasPrecision(16, 8);

            modelBuilder.Entity<ExchangeSession>().Property(x => x.OpeningTime).HasPrecision(0);
            modelBuilder.Entity<ExchangeSession>().Property(x => x.ClosingTime).HasPrecision(0);

            modelBuilder.Entity<InstrumentSession>().Property(x => x.OpeningTime).HasPrecision(0);
            modelBuilder.Entity<InstrumentSession>().Property(x => x.ClosingTime).HasPrecision(0);

            modelBuilder.Entity<TemplateSession>().Property(x => x.OpeningTime).HasPrecision(0);
            modelBuilder.Entity<TemplateSession>().Property(x => x.ClosingTime).HasPrecision(0);

            string uniqueIndex = "IX_Unique";

            modelBuilder.Entity<Instrument>().Property(t => t.Symbol)
                .HasColumnAnnotation(
                    IndexAnnotation.AnnotationName,
                    new IndexAnnotation(
                        new IndexAttribute(uniqueIndex)
                        {
                            IsUnique = true,
                            Order = 1
                        }
                    )
                );

            modelBuilder.Entity<Instrument>().Property(t => t.Type)
                .HasColumnAnnotation(
                    IndexAnnotation.AnnotationName,
                    new IndexAnnotation(
                        new IndexAttribute(uniqueIndex)
                        {
                            IsUnique = true,
                            Order = 2
                        }
                    )
                );

            modelBuilder.Entity<Instrument>().Property(t => t.DatasourceID)
                .HasColumnAnnotation(
                    IndexAnnotation.AnnotationName,
                    new IndexAnnotation(
                        new IndexAttribute(uniqueIndex)
                        {
                            IsUnique = true,
                            Order = 3
                        }
                    )
                );

            modelBuilder.Entity<Instrument>().Property(t => t.ExchangeID)
                .HasColumnAnnotation(
                    IndexAnnotation.AnnotationName,
                    new IndexAnnotation(
                        new IndexAttribute(uniqueIndex)
                        {
                            IsUnique = true,
                            Order = 4
                        }
                    )
                );

            modelBuilder.Entity<Instrument>().Property(t => t.Expiration)
                .HasColumnAnnotation(
                    IndexAnnotation.AnnotationName,
                    new IndexAnnotation(
                        new IndexAttribute(uniqueIndex)
                        {
                            IsUnique = true,
                            Order = 5
                        }
                    )
                );

            modelBuilder.Entity<Instrument>().Property(t => t.Strike)
                .HasColumnAnnotation(
                    IndexAnnotation.AnnotationName,
                    new IndexAnnotation(
                        new IndexAttribute(uniqueIndex)
                        {
                            IsUnique = true,
                            Order = 6
                        }
                    )
                );



            Database.SetInitializer(new MigrateDatabaseToLatestVersion<MyDBContext, MyDbContextConfiguration>());
        }
    }
}
{'fraction_non_alphanumeric': 0.12685630621208951, 'fraction_numerical': 0.00397406400334658, 'mean_word_length': 1.6976022566995768, 'pattern_counts': {'":': 0, '<': 63, '<?xml version=': 0, '>': 89, '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': '3187035', 'n_tokens_mistral': 2369, 'n_tokens_neox': 2200, 'n_words': 354}