// ReSharper disable UnusedMember.Local
        private void AddEntityType <TEntityConfiguration, TEntityType>()
        // ReSharper restore UnusedMember.Local
            where TEntityConfiguration : EntityTypeConfiguration <TEntityType>, new()
            where TEntityType : class
        {
            var configuration = new TEntityConfiguration();

            this.modelBuilder.Configurations.Add(configuration);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Returns the <see cref="EntityTypeBuilder"/> of the given entity
        /// </summary>
        /// <typeparam name="TEntity">The entity</typeparam>
        /// <typeparam name="TEntityConfiguration">The entitie's configuration</typeparam>
        /// <returns>EntityTypeBuilder<TEntity></returns>
        public static EntityTypeBuilder <TEntity> GetEntityTypeBuilder <TEntity, TEntityConfiguration>()
            where TEntity : class
            where TEntityConfiguration : IEntityTypeConfiguration <TEntity>, new()
        {
            var options = new DbContextOptionsBuilder <ShopDbContext>()
                          .UseSqlite(new SqliteConnection("DataSource=:memory:"))
                          .Options;

            var sut           = new ShopDbContext(options);
            var conventionSet = ConventionSet.CreateConventionSet(sut);
            var modelBuilder  = new ModelBuilder(conventionSet);

            var entityBuilder = modelBuilder.Entity <TEntity>();
            var entityConfig  = new TEntityConfiguration();

            entityConfig.Configure(entityBuilder);

            return(entityBuilder);
        }