Esempio n. 1
0
        protected override void OnModelCreating(System.Data.Entity.DbModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);

            modelBuilder.Properties().Where(p => p.DeclaringType == typeof(string)).Configure(p => p.HasMaxLength(1000));

            modelBuilder.Properties().Where(p => p.DeclaringType == typeof(string)).Configure(p => p.HasColumnType("NVarchar"));
        }
        protected override void OnModelCreating(System.Data.Entity.DbModelBuilder modelBuilder)
        {
            modelBuilder.Properties().Where(p => p.Name.StartsWith("Pk"))
            .Configure(p => p.IsKey());

            modelBuilder.Properties <string>()
            .Where(p => p.Name.Contains("Title") ||
                   p.Name.Contains("Name") ||
                   p.Name.Contains("Email")
                   ).Configure(p => p.HasMaxLength(200));

            modelBuilder.Properties()
            .Configure(p => p.HasColumnName(GetColumnName(p.ClrPropertyInfo)));
        }
Esempio n. 3
0
        protected override void OnModelCreating(System.Data.Entity.DbModelBuilder modelBuilder)
        {
            modelBuilder.Entity <ApplicationUser>().Property(x => x.Balance).HasPrecision(18, 8);
            modelBuilder.Properties <decimal>().Configure(x => x.HasPrecision(18, 8));

            base.OnModelCreating(modelBuilder);
        }
Esempio n. 4
0
        protected override void OnModelCreating(System.Data.Entity.DbModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);

            #region Remove convenções
            modelBuilder.Conventions.Remove <PluralizingTableNameConvention>();
            modelBuilder.Conventions.Remove <OneToManyCascadeDeleteConvention>();
            modelBuilder.Conventions.Remove <ManyToManyCascadeDeleteConvention>();
            #endregion

            #region Convenção varchar
            modelBuilder.Properties <string>()
            .Configure(p => p.HasColumnType("varchar"));

            modelBuilder.Properties <string>()
            .Configure(p => p.HasMaxLength(256));
            #endregion

            #region Tabelas de usuários
            modelBuilder.Entity <User>().ToTable("Users").Property(x => x.Id).HasColumnName("UserId");
            modelBuilder.Entity <User>().Property(x => x.Email).IsRequired().HasMaxLength(256).HasColumnAnnotation("Index", new IndexAnnotation(new IndexAttribute("IX_Email")
            {
                IsUnique = true
            }));
            modelBuilder.Entity <User>().Property(x => x.UserName).IsRequired().HasMaxLength(256).HasColumnAnnotation("Index", new IndexAnnotation(new IndexAttribute("IX_Username")
            {
                IsUnique = true
            }));
            modelBuilder.Entity <IdentityUserRole>().ToTable("UserRoles").Property(x => x.UserId).HasColumnName("UserId");
            modelBuilder.Entity <IdentityUserLogin>().ToTable("UserLogins").Property(x => x.UserId).HasColumnName("UserId");
            modelBuilder.Entity <IdentityUserClaim>().ToTable("UserClaims").Property(x => x.UserId).HasColumnName("UserId");
            modelBuilder.Entity <IdentityRole>().ToTable("Roles");
            #endregion

            #region -- Model Mapping --
            modelBuilder.Configurations.Add(new CoordinatorMapping());
            modelBuilder.Configurations.Add(new StudentMapping());
            modelBuilder.Configurations.Add(new SecretaryMapping());
            modelBuilder.Configurations.Add(new ScoreMapping());
            modelBuilder.Configurations.Add(new SchoolClassMapping());
            modelBuilder.Configurations.Add(new SubjectMapping());
            modelBuilder.Configurations.Add(new CourseMapping());
            #endregion
        }
        protected override void OnModelCreating(System.Data.Entity.DbModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);

            modelBuilder.Entity <ApplicationUser>().ToTable("User").Property(p => p.Id).HasColumnName("UserId");
            modelBuilder.Entity <IdentityUserRole>().ToTable("UserRole");
            modelBuilder.Entity <IdentityUserLogin>().ToTable("UserLogin");
            modelBuilder.Entity <IdentityUserClaim>().ToTable("UserClaim").Property(p => p.Id).HasColumnName("UserClaim");
            modelBuilder.Entity <IdentityRole>().ToTable("Role").Property(p => p.Id).HasColumnName("RoleId");
            modelBuilder.Properties <decimal>().Configure(c => c.HasPrecision(18, 2));

            modelBuilder.Conventions.Remove <OneToManyCascadeDeleteConvention>();
        }
Esempio n. 6
0
        protected override void OnModelCreating(System.Data.Entity.DbModelBuilder modelBuilder)
        {
            modelBuilder.Properties().Where(p => p.Name.StartsWith("Pk"))
            .Configure(p => p.IsKey());

            modelBuilder.Properties <string>()
            .Where(p => p.Name.Contains("Title") ||
                   p.Name.Contains("Name") ||
                   p.Name.Contains("Email")
                   ).Configure(p => p.HasMaxLength(200));
            modelBuilder.Properties()
            .Configure(p => p.HasColumnName(GetColumnName(p.ClrPropertyInfo)));

            //modelBuilder
            //    .Entity<Post>()
            //    .MapToStoredProcedures();

            modelBuilder
            .Entity <Post>()
            .MapToStoredProcedures(sp =>
                                   sp.Update(u => u.HasName("UpdatePost").Parameter(p => p.Content, "post_content")));
        }
Esempio n. 7
0
        protected override void OnModelCreating(System.Data.Entity.DbModelBuilder modelBuilder)
        {
            Database.SetInitializer <ProjetoModeloContext>(null);
            //Database.SetInitializer<ProjetoModeloContext>(new CreateDatabaseIfNotExists<ProjetoModeloContext>());

            modelBuilder.Conventions.Remove <PluralizingTableNameConvention>();
            modelBuilder.Conventions.Remove <OneToManyCascadeDeleteConvention>();
            modelBuilder.Conventions.Remove <ManyToManyCascadeDeleteConvention>();

//modelBuilder.Properties().Where(p=>p.Name==p.ReflectedType+"Id").Configure(p=>p.IsKey());
            modelBuilder.Properties()
            .Where(p => p.Name == p.ReflectedType.Name + "Id")
            .Configure(p => p.IsKey());

            modelBuilder.Properties <string>()
            .Configure(p => p.HasColumnType("varchar"));

            modelBuilder.Properties <string>()
            .Configure(p => p.HasMaxLength(100));

            modelBuilder.Configurations.Add(new ClienteConfiguration());
            modelBuilder.Configurations.Add(new ProdutoConfiguration());
        }