Exemple #1
0
        /// <inheritdoc />
        public override void OnModelCreating(ModelConfigurationBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);

            modelBuilder.Entity <Workshop>()
            .HasTableName(WorkshopsTableName)
            .HasPrimaryKey(f => f.Id).AutoIncrement()
            .UseConverterForProperties <string>(NullAndTrimStringConverter.ConvertNull)
            .Property(f => f.CreatedTimestamp).UseCurrentTimeValueGenerator(ValueGenerated.OnInsert)
            .Property(f => f.LastModifiedTimestamp).UseCurrentTimeValueGenerator(ValueGenerated.OnInsertOrUpdate)
            .Property(f => f.CreatedBy).UseValueGeneratorOnInsert(new CurrentUserValueGenerator(ServiceProvider))
            .Property(f => f.LastModifiedBy).UseValueGeneratorOnInsertOrUpdate(new CurrentUserValueGenerator(ServiceProvider));

            modelBuilder.Entity <Person>()
            .HasTableName(PeopleTableName)
            .HasPrimaryKey(f => f.Id).AutoIncrement()
            .UseConverterForProperties <string>(NullAndTrimStringConverter.ConvertNull)
            .Property(f => f.CreatedTimestamp).UseCurrentTimeValueGenerator(ValueGenerated.OnInsert)
            .Property(f => f.LastModifiedTimestamp).UseCurrentTimeValueGenerator(ValueGenerated.OnInsertOrUpdate)
            .Property(f => f.CreatedBy).UseValueGeneratorOnInsert(new CurrentUserValueGenerator(ServiceProvider))
            .Property(f => f.LastModifiedBy).UseValueGeneratorOnInsertOrUpdate(new CurrentUserValueGenerator(ServiceProvider));

            modelBuilder.Entity <Attendance>()
            .HasTableName(AttendanceTableName)
            .HasPrimaryKey(f => f.Id).AutoIncrement();
        }
        public override void OnModelCreating(ModelConfigurationBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);

            modelBuilder.Entity <Photo>()
            .HasTableName("Photos")
            .HasPrimaryKey(p => p.Id).AutoIncrement();
        }
        public override void OnModelCreating(ModelConfigurationBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);

            modelBuilder.Entity <Product>()
            .HasTableName("Products")
            .HasPrimaryKey(p => p.Id).AutoIncrement(AutoIncrementMethodType.Identity);
        }
Exemple #4
0
 /// <summary>
 /// Create database model.
 /// </summary>
 /// <param name="modelBuilder"><see cref="ModelConfigurationBuilder"/></param>
 public override void OnModelCreating(ModelConfigurationBuilder modelBuilder)
 {
     modelBuilder.Entity <RRREntityNameRRR_>()
     .HasTableName(RRREntityNameRRR_Plural_TableName)
     .HasPrimaryKey(f => f.Id).AutoIncrement()
     .UseConverterForProperties <string>(NullAndTrimStringConverter.ConvertNull)
     .Property(f => f.CreatedTimestamp).UseCurrentTimeValueGenerator(ValueGenerated.OnInsert)
     .Property(f => f.LastModifiedTimestamp).UseCurrentTimeValueGenerator(ValueGenerated.OnInsertOrUpdate);
 }
Exemple #5
0
        public override void OnModelCreating(ModelConfigurationBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);

            modelBuilder.Entity <Order>()
            .HasTableName("Orders")
            .HasPrimaryKey(p => p.Id).AutoIncrement(AutoIncrementMethodType.Identity)
            .Property(p => p.Items).UseConverter <JsonConverter <List <OrderItem> > >();
        }
Exemple #6
0
            public override void OnModelCreating(ModelConfigurationBuilder modelBuilder)
            {
                base.OnModelCreating(modelBuilder);

                modelBuilder.Entity <Bar>()
                .HasTableName("Foo")
                .HasPrimaryKey(p => p.RowId)
                .Property(p => p.RowId).HasColumnName("Id")
                .Property(p => p.Age).HasColumnName("Value");
            }
Exemple #7
0
        public void ThrowExceptionWhenMappingTheTheSamePropertyMoreThanOnce()
        {
            Action builderAction = () =>
            {
                var modelBuilder = new ModelConfigurationBuilder();
                modelBuilder.Entity <ConvertersEntity>()
                .Property(p => p.StringProp1).UseConverter <StringConverter2>()
                .Property(p => p.StringProp1).IgnoreConverter();
            };

            builderAction.Should().Throw <InvalidOperationException>();
        }
Exemple #8
0
        public void ThrowExceptionWhenUseCurrentTimeGeneratorOnNever()
        {
            var modelBuilder = new ModelConfigurationBuilder();
            var modelMapper  = new ConventionModelMapper();

            Action act = () =>
                         modelBuilder.Entity <BuilderTestEntity>()
                         .Property(p => p.GeneratedValue)
                         .UseCurrentTimeValueGenerator(ValueGenerated.Never);

            act.Should().Throw <NotSupportedException>();
        }
Exemple #9
0
            public override void OnModelCreating(ModelConfigurationBuilder modelBuilder)
            {
                base.OnModelCreating(modelBuilder);

                modelBuilder.Table("Foo")
                .UseQueryFilter <Foo>(f => f.Value > 2);

                modelBuilder.Entity <Foo2>()
                .HasTableName("Foo");

                modelBuilder.Entity <Bar>()
                .HasTableName("Bars");

                modelBuilder.Table("Bars").UseQueryFilter <Bar>(b => b.Value.StartsWith("Slov"));

                modelBuilder.Table("FooBar")
                .UseQueryFilter <FooBar>(f => f.Value > GetValue());

                modelBuilder.Table("ComplexCondition")
                .UseQueryFilter <ComplexCondition>(f => (f.Value > 1 && f.Value < 1000) || f.Id > 0);
            }
        public void UseEmptyQuota()
        {
            var modelBuilder = new ModelConfigurationBuilder();
            var modelMapper  = new ConventionModelMapper();

            modelBuilder.Entity <BuilderTestEntity>()
            .HasTableName("BuilderTest");

            modelBuilder.Build(modelMapper);

            TableInfo tableInfo = modelMapper.GetTableInfo <BuilderTestEntity>();

            tableInfo.Delimiters.Should().Be(Delimiters.Empty);
        }
Exemple #11
0
        public void DoNotReturnQueryFilterIfWasNotConfigured()
        {
            var modelBuilder = new ModelConfigurationBuilder();
            var modelMapper  = new ConventionModelMapper();

            modelBuilder.Entity <FooQueryFilter>()
            .HasTableName("Foo");

            modelBuilder.Build(modelMapper);

            TableInfo tableInfo = modelMapper.GetTableInfo <FooQueryFilter>();

            tableInfo.QueryFilter
            .Should().BeNull();
        }
Exemple #12
0
        public void UseCurrentTimeGeneratorOnInsert()
        {
            var modelBuilder = new ModelConfigurationBuilder();
            var modelMapper  = new ConventionModelMapper();

            modelBuilder.Entity <BuilderTestEntity>()
            .Property(p => p.GeneratedValue).UseCurrentTimeValueGenerator(ValueGenerated.OnInsert);

            modelBuilder.Build(modelMapper);

            TableInfo tableInfo = modelMapper.GetTableInfo <BuilderTestEntity>();

            tableInfo.GetColumnInfoByPropertyName("GeneratedValue").ValueGenerated.Should().Be(ValueGenerated.OnInsert);
            tableInfo.GetColumnInfoByPropertyName("GeneratedValue").ValueGenerator.Should().BeOfType <CurrentTimeValueGenerator>();
        }
        public void SetNamingQuota()
        {
            var modelBuilder = new ModelConfigurationBuilder();
            var modelMapper  = new ConventionModelMapper();

            modelBuilder.UseIdentifierDelimiters(Delimiters.SquareBrackets);
            modelBuilder.Entity <BuilderTestEntity>()
            .HasTableName("BuilderTest");

            modelBuilder.Build(modelMapper);

            TableInfo tableInfo = modelMapper.GetTableInfo <BuilderTestEntity>();

            tableInfo.Delimiters.Should().Be(Delimiters.SquareBrackets);
        }
Exemple #14
0
        public void BuildConfiguration()
        {
            var modelBuilder = new ModelConfigurationBuilder();
            var modelMapper  = new ConventionModelMapper();

            modelBuilder.Entity <BuilderTestEntity>()
            .HasTableName("BuilderTest")
            .HasPrimaryKey(f => f.Id).AutoIncrement(AutoIncrementMethodType.Custom)
            .Property(p => p.Address)
            .HasColumnName("COL_ADDRESS")
            .UseConverter <AddressConverter>()
            .Property(p => p.NoMapped).NoMap()
            .Property(p => p.FirstName).HasColumnName("Name")
            .Property(p => p.DateTime).InjectValue(() => DateTime.Now)
            .Property(p => p.GeneratedValue).UseValueGeneratorOnInsert <AutoIncrementValueGenerator>();

            modelBuilder.Build(modelMapper);

            TableInfo tableInfo = modelMapper.GetTableInfo <BuilderTestEntity>();

            var columns = new List <ColumnInfo>()
            {
                new ColumnInfo()
                {
                    Name                    = "Id",
                    IsPrimaryKey            = true,
                    AutoIncrementMethodType = AutoIncrementMethodType.Custom
                },
                new ColumnInfo()
                {
                    Name = "COL_ADDRESS", Converter = new AddressConverter()
                },
                new ColumnInfo()
                {
                    Name = "Name"
                },
                new ColumnInfo()
                {
                    Name = "GeneratedValue", ValueGenerator = new AutoIncrementValueGenerator()
                }
            };
            TableInfo tableInfoExpected = CreateExpectedTableInfo(columns, "BuilderTest");

            AreSame(tableInfo, tableInfoExpected);
            modelMapper.GetInjector <BuilderTestEntity>().IsInjectable("DateTime")
            .Should()
            .BeTrue("DateTime property has injector.");
        }
Exemple #15
0
        public void UseQueryFilter()
        {
            var modelBuilder = new ModelConfigurationBuilder();
            var modelMapper  = new ConventionModelMapper();

            modelBuilder.Entity <FooQueryFilter>()
            .HasTableName("Foo");

            modelBuilder.Table("Foo")
            .UseQueryFilter <FooQueryFilter>(f => f.AutorId == 5);

            modelBuilder.Build(modelMapper);

            TableInfo tableInfo = modelMapper.GetTableInfo <FooQueryFilter>();

            tableInfo.QueryFilter
            .Should().NotBeNull();
        }
Exemple #16
0
        public void UseConverterForAllPropertiesOfSpecifiedType()
        {
            var modelBuilder = new ModelConfigurationBuilder();
            var modelMapper  = new ConventionModelMapper();

            modelBuilder.Entity <ConvertersEntity>()
            .UseConverterForProperties <int>(new IntConverter())
            .UseConverterForProperties <string, StringConverter1>()
            .Property(p => p.StringPropWithOwnConverter).UseConverter <StringConverter2>()
            .Property(p => p.StringPropWithoutConverter).IgnoreConverter();

            modelBuilder.Build(modelMapper);

            TableInfo tableInfo = modelMapper.GetTableInfo <ConvertersEntity>();

            ColumnInfo intProp1 = tableInfo.GetColumnInfo(nameof(ConvertersEntity.IntProp1));
            ColumnInfo intProp2 = tableInfo.GetColumnInfo(nameof(ConvertersEntity.IntProp1));

            intProp1.Converter
            .Should().BeOfType <IntConverter>()
            .And.Be(intProp2.Converter);

            ColumnInfo stringProp1 = tableInfo.GetColumnInfo(nameof(ConvertersEntity.StringProp1));
            ColumnInfo stringProp2 = tableInfo.GetColumnInfo(nameof(ConvertersEntity.StringProp2));
            ColumnInfo stringProp3 = tableInfo.GetColumnInfo(nameof(ConvertersEntity.StringProp3));
            ColumnInfo stringProp4 = tableInfo.GetColumnInfo(nameof(ConvertersEntity.StringProp4));

            stringProp1.Converter
            .Should().BeOfType <StringConverter1>()
            .And.Be(stringProp2.Converter)
            .And.Be(stringProp3.Converter)
            .And.Be(stringProp4.Converter);

            ColumnInfo stringPropWithOwnConverter = tableInfo.GetColumnInfo(nameof(ConvertersEntity.StringPropWithOwnConverter));

            stringPropWithOwnConverter.Converter.Should().BeOfType <StringConverter2>();

            ColumnInfo stringPropWithoutConverter = tableInfo.GetColumnInfo(nameof(ConvertersEntity.StringPropWithoutConverter));

            stringPropWithoutConverter.Converter.Should().BeNull();

            tableInfo.GetColumnInfo(nameof(ConvertersEntity.BoolProp)).Converter.Should().BeNull();
            tableInfo.GetColumnInfo(nameof(ConvertersEntity.DateTimeProp)).Converter.Should().BeNull();
        }
Exemple #17
0
        public void BuildConfigurationWhenRenamePropertyForPrimaryKey()
        {
            var modelBuilder = new ModelConfigurationBuilder();
            var modelMapper  = new ConventionModelMapper();

            modelBuilder.Entity <Foo>()
            .HasTableName("FooTable")
            .HasPrimaryKey(f => f.FooId).AutoIncrement()
            .Property(p => p.FooId).HasColumnName("RowId");

            modelBuilder.Build(modelMapper);

            TableInfo tableInfo = modelMapper.GetTableInfo <Foo>();

            var columns = new List <ColumnInfo>()
            {
                new ColumnInfo()
                {
                    Name                    = "RowId",
                    IsPrimaryKey            = true,
                    AutoIncrementMethodType = AutoIncrementMethodType.Identity
                },
                new ColumnInfo()
                {
                    Name = "Addresses"
                },
                new ColumnInfo()
                {
                    Name = "FirstName"
                },
                new ColumnInfo()
                {
                    Name = "NoMapped"
                },
                new ColumnInfo()
                {
                    Name = "DateTime"
                }
            };
            TableInfo tableInfoExpected = CreateExpectedTableInfo(columns, "FooTable");

            AreSame(tableInfo, tableInfoExpected);
        }
Exemple #18
0
        public void BuildConfigurationWhenAutoIncrementMethodTypeIsNotSet()
        {
            var modelBuilder = new ModelConfigurationBuilder();
            var modelMapper  = new ConventionModelMapper();

            modelBuilder.Entity <Foo>()
            .HasPrimaryKey(f => f.FooId);

            modelBuilder.Build(modelMapper);

            TableInfo tableInfo = modelMapper.GetTableInfo <Foo>();

            var columns = new List <ColumnInfo>()
            {
                new ColumnInfo()
                {
                    Name                    = "FooId",
                    IsPrimaryKey            = true,
                    AutoIncrementMethodType = AutoIncrementMethodType.None
                },
                new ColumnInfo()
                {
                    Name = "Addresses"
                },
                new ColumnInfo()
                {
                    Name = "FirstName"
                },
                new ColumnInfo()
                {
                    Name = "NoMapped"
                },
                new ColumnInfo()
                {
                    Name = "DateTime"
                }
            };
            TableInfo tableInfoExpected = CreateExpectedTableInfo(columns, "Foo");

            AreSame(tableInfo, tableInfoExpected);
        }
Exemple #19
0
 public override void OnModelCreating(ModelConfigurationBuilder modelBuilder)
 => modelBuilder.Entity <PersonDbConfig>()
 .HasTableName(TestTableNameA)
 .HasPrimaryKey(entity => entity.IdA).AutoIncrement(AutoIncrementMethodType.Custom, ConfiguredGeneratorName);
Exemple #20
0
 /// <summary>
 /// Create database model.
 /// </summary>
 /// <param name="modelBuilder"><see cref="ModelConfigurationBuilder"/></param>
 public override void OnModelCreating(ModelConfigurationBuilder modelBuilder)
 {
     modelBuilder.Entity <RRREntityNameRRR_>()
     .HasTableName(RRREntityNameRRR_Plural_TableName)
     .HasPrimaryKey(f => f.Id).AutoIncrement();
 }
Exemple #21
0
        public void BuildConfigurationForTwoEntities()
        {
            var modelBuilder = new ModelConfigurationBuilder();
            var modelMapper  = new ConventionModelMapper();

            modelBuilder.Entity <Foo>()
            .HasTableName("FooTable")
            .HasPrimaryKey(f => f.FooId).AutoIncrement(AutoIncrementMethodType.Custom)
            .Property(p => p.Addresses)
            .HasColumnName("COL_ADDRESSES")
            .UseConverter <AddressConverter>()
            .Property(p => p.NoMapped).NoMap()
            .Property(p => p.FirstName).HasColumnName("Name")
            .Property(p => p.DateTime).InjectValue(() => DateTime.Now);

            modelBuilder.Entity <Bar>()
            .Property(p => p.FirstName)
            .HasColumnName("GivenName")
            .UseConverter(new UpperCaseConverter());

            modelBuilder.Build(modelMapper);

            TableInfo tableInfo = modelMapper.GetTableInfo <Foo>();

            var columns = new List <ColumnInfo>()
            {
                new ColumnInfo()
                {
                    Name                    = "FooId",
                    IsPrimaryKey            = true,
                    AutoIncrementMethodType = AutoIncrementMethodType.Custom
                },
                new ColumnInfo()
                {
                    Name = "COL_ADDRESSES", Converter = new AddressConverter()
                },
                new ColumnInfo()
                {
                    Name = "Name"
                }
            };
            TableInfo tableInfoFooExpected = CreateExpectedTableInfo(columns, "FooTable");

            AreSame(tableInfo, tableInfoFooExpected);

            TableInfo tableInfoBar = modelMapper.GetTableInfo <Bar>();

            columns = new List <ColumnInfo>()
            {
                new ColumnInfo()
                {
                    Name                    = "Id",
                    IsPrimaryKey            = true,
                    AutoIncrementMethodType = AutoIncrementMethodType.None
                },
                new ColumnInfo()
                {
                    Name = "GivenName", Converter = new UpperCaseConverter()
                },
                new ColumnInfo()
                {
                    Name = "LastName"
                }
            };
            TableInfo tableInfoBarExpected = CreateExpectedTableInfo(columns, "Bar");

            AreSame(tableInfoBar, tableInfoBarExpected);
        }