Ejemplo n.º 1
0
        public void Sequence_specified_on_property_is_shared_if_same_name_used()
        {
            var modelBuilder = new BasicModelBuilder();

            modelBuilder
            .Entity("A",
                    b =>
            {
                b.Property <int>("Id").ForSqlServer().UseSequence("MySequence");
                b.Property <short>("P").ForSqlServer().UseSequence("MySequence");
                b.Key("Id");
            });

            var databaseBuilder = new SqlServerDatabaseBuilder(new SqlServerTypeMapper());
            var database        = databaseBuilder.GetDatabase(modelBuilder.Model);

            Assert.Equal(1, database.Sequences.Count);

            var sequence = database.Sequences[0];

            Assert.Equal("MySequence", sequence.Name);
            Assert.Equal("bigint", sequence.DataType);
            Assert.Equal(1, sequence.StartWith);
            Assert.Equal(10, sequence.IncrementBy);
        }
Ejemplo n.º 2
0
        public void Build_creates_sequence_only_named_on_model_with_schema()
        {
            var modelBuilder = new BasicModelBuilder();

            modelBuilder.ForSqlServer().UseSequence("MySequence", "dbOh");

            modelBuilder.Entity("A", b =>
            {
                b.Property <int>("Id").GenerateValuesOnAdd();
                b.Key("Id");
            });
            modelBuilder.Entity("B", b =>
            {
                b.Property <short>("Id").GenerateValuesOnAdd();
                b.Key("Id");
            });

            var databaseBuilder = new SqlServerDatabaseBuilder(new SqlServerTypeMapper());
            var database        = databaseBuilder.GetDatabase(modelBuilder.Model);

            Assert.Equal(1, database.Sequences.Count);

            var sequence = database.Sequences[0];

            Assert.Equal("dbOh.MySequence", sequence.Name);
            Assert.Equal("bigint", sequence.DataType);
            Assert.Equal(1, sequence.StartWith);
            Assert.Equal(10, sequence.IncrementBy);
        }
Ejemplo n.º 3
0
        public void Can_use_model_default_and_named_property_specific_sequence_with_schema()
        {
            var modelBuilder = new BasicModelBuilder();

            modelBuilder
            .ForSqlServer(
                b => { b.UseSequence(); })
            .Entity("A",
                    b =>
            {
                b.Property <int>("Id").ForSqlServer().UseSequence("S0", "dbOh");
                b.Property <short>("P").ForSqlServer().UseSequence();
                b.Key("Id");
            });

            var databaseBuilder = new SqlServerDatabaseBuilder(new SqlServerTypeMapper());
            var database        = databaseBuilder.GetDatabase(modelBuilder.Model);

            Assert.Equal(2, database.Sequences.Count);

            var sequence0 = database.Sequences[0];

            Assert.Equal("dbOh.S0", sequence0.Name);
            Assert.Equal("bigint", sequence0.DataType);
            Assert.Equal(1, sequence0.StartWith);
            Assert.Equal(10, sequence0.IncrementBy);

            var sequence1 = database.Sequences[1];

            Assert.Equal("EntityFrameworkDefaultSequence", sequence1.Name);
            Assert.Equal("bigint", sequence0.DataType);
            Assert.Equal(1, sequence0.StartWith);
            Assert.Equal(10, sequence1.IncrementBy);
        }
Ejemplo n.º 4
0
        public void Sequence_specified_on_property_is_shared_if_matches_previous_definition_with_schema()
        {
            var modelBuilder = new BasicModelBuilder();

            modelBuilder
            .ForSqlServer(
                b => { b.Sequence("MySequence", "dbOh").IncrementBy(7); })
            .Entity("A",
                    b =>
            {
                b.Property <int>("Id").ForSqlServer().UseSequence("MySequence", "dbOh");
                b.Property <short>("P").ForSqlServer().UseSequence("MySequence", "dbOh");
                b.Key("Id");
            });

            var databaseBuilder = new SqlServerDatabaseBuilder(new SqlServerTypeMapper());
            var database        = databaseBuilder.GetDatabase(modelBuilder.Model);

            Assert.Equal(1, database.Sequences.Count);

            var sequence = database.Sequences[0];

            Assert.Equal("dbOh.MySequence", sequence.Name);
            Assert.Equal("bigint", sequence.DataType);
            Assert.Equal(1, sequence.StartWith);
            Assert.Equal(7, sequence.IncrementBy);
        }
Ejemplo n.º 5
0
        public void Build_creates_sequence_defined_on_model_with_defaults()
        {
            var modelBuilder = new BasicModelBuilder();

            modelBuilder.ForSqlServer().UseSequence();

            modelBuilder.Entity("A", b =>
            {
                b.Property <int>("Id").GenerateValuesOnAdd();
                b.Key("Id");
                b.ForSqlServer().Table("T0", "dbo");
            });

            modelBuilder.Entity("B", b =>
            {
                b.Property <short>("Id").GenerateValuesOnAdd();
                b.Key("Id");
                b.ForSqlServer().Table("T1", "dbo");
            });

            var databaseBuilder = new SqlServerDatabaseBuilder(new SqlServerTypeMapper());
            var database        = databaseBuilder.GetDatabase(modelBuilder.Model);

            Assert.Equal(1, database.Sequences.Count);

            var sequence = database.Sequences[0];

            Assert.Equal("EntityFrameworkDefaultSequence", sequence.Name);
            Assert.Equal("bigint", sequence.DataType);
            Assert.Equal(1, sequence.StartWith);
            Assert.Equal(10, sequence.IncrementBy);
        }
Ejemplo n.º 6
0
        public void Diff_finds_created_sequence()
        {
            var sourceModelBuilder = new BasicModelBuilder();

            sourceModelBuilder.Entity("A",
                                      b =>
            {
                b.Property <int>("Id").ForSqlServer().UseSequence("S1", "dbo");
                b.Property <short>("P");
                b.Key("Id");
            });

            var targetModelBuilder = new BasicModelBuilder();

            targetModelBuilder.Entity("A",
                                      b =>
            {
                b.Property <int>("Id").ForSqlServer().UseSequence("S1", "dbo");
                b.Property <short>("P").ForSqlServer().UseSequence("S2", "dbo");
                b.Key("Id");
            });

            var databaseBuilder = new SqlServerDatabaseBuilder(new SqlServerTypeMapper());
            var operations      = new SqlServerModelDiffer(databaseBuilder).Diff(
                sourceModelBuilder.Model, targetModelBuilder.Model);
            var sourceDbModel = databaseBuilder.GetDatabase(sourceModelBuilder.Model);
            var targetDbModel = databaseBuilder.GetDatabase(targetModelBuilder.Model);

            Assert.Equal(2, operations.Count);
            Assert.IsType <CreateSequenceOperation>(operations[0]);
            Assert.IsType <AlterColumnOperation>(operations[1]);

            var createSequenceOperation = (CreateSequenceOperation)operations[0];

            Assert.Same(targetDbModel.Sequences[1], createSequenceOperation.Sequence);

            var alterColumnOperation = (AlterColumnOperation)operations[1];

            Assert.Equal(ValueGeneration.None, sourceDbModel.GetTable(alterColumnOperation.TableName).GetColumn(alterColumnOperation.NewColumn.Name).ValueGenerationStrategy);
            Assert.Equal(ValueGeneration.OnAdd, alterColumnOperation.NewColumn.ValueGenerationStrategy);
        }
Ejemplo n.º 7
0
        public void Build_creates_sequence_specified_on_property_with_schema()
        {
            var modelBuilder = new BasicModelBuilder();

            modelBuilder
            .ForSqlServer(
                b =>
            {
                b.Sequence("S0", "dbOh")
                .IncrementBy(3)
                .Start(1001)
                .Min(1000)
                .Max(2000)
                .Type <int>();

                b.Sequence("S1", "dbOh")
                .IncrementBy(7)
                .Start(7001)
                .Min(7000)
                .Max(9000)
                .Type <short>();
            })
            .Entity("A",
                    b =>
            {
                b.Property <int>("Id").ForSqlServer().UseSequence("S0", "dbOh");
                b.Property <short>("P").ForSqlServer().UseSequence("S1", "dbOh");
                b.Key("Id");
            });

            var databaseBuilder = new SqlServerDatabaseBuilder(new SqlServerTypeMapper());
            var database        = databaseBuilder.GetDatabase(modelBuilder.Model);

            Assert.Equal(2, database.Sequences.Count);

            var sequence0 = database.Sequences[0];

            Assert.Equal("dbOh.S0", sequence0.Name);
            Assert.Equal("int", sequence0.DataType);
            Assert.Equal(1001, sequence0.StartWith);
            Assert.Equal(3, sequence0.IncrementBy);

            var sequence1 = database.Sequences[1];

            Assert.Equal("dbOh.S1", sequence1.Name);
            Assert.Equal("smallint", sequence1.DataType);
            Assert.Equal(7001, sequence1.StartWith);
            Assert.Equal(7, sequence1.IncrementBy);
        }
Ejemplo n.º 8
0
        public void Can_use_configured_default_and_configured_property_specific_sequence()
        {
            var modelBuilder = new BasicModelBuilder();

            modelBuilder
            .ForSqlServer(
                b =>
            {
                b.Sequence("S0").IncrementBy(3);
                b.Sequence("S1").IncrementBy(7);
                b.UseSequence("S1");
            })
            .Entity("A",
                    b =>
            {
                b.Property <int>("Id").ForSqlServer().UseSequence("S0");
                b.Property <short>("P").ForSqlServer().UseSequence();
                b.Key("Id");
            });

            var databaseBuilder = new SqlServerDatabaseBuilder(new SqlServerTypeMapper());
            var database        = databaseBuilder.GetDatabase(modelBuilder.Model);

            Assert.Equal(2, database.Sequences.Count);

            var sequence0 = database.Sequences[0];

            Assert.Equal("S0", sequence0.Name);
            Assert.Equal("bigint", sequence0.DataType);
            Assert.Equal(1, sequence0.StartWith);
            Assert.Equal(3, sequence0.IncrementBy);

            var sequence1 = database.Sequences[1];

            Assert.Equal("S1", sequence1.Name);
            Assert.Equal("bigint", sequence0.DataType);
            Assert.Equal(1, sequence0.StartWith);
            Assert.Equal(7, sequence1.IncrementBy);
        }