当前位置: 首页>>代码示例>>C#>>正文


C# DbModelBuilder.Properties方法代码示例

本文整理汇总了C#中DbModelBuilder.Properties方法的典型用法代码示例。如果您正苦于以下问题:C# DbModelBuilder.Properties方法的具体用法?C# DbModelBuilder.Properties怎么用?C# DbModelBuilder.Properties使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DbModelBuilder的用法示例。


在下文中一共展示了DbModelBuilder.Properties方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: OnModelCreating

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
            modelBuilder.Conventions
                .Remove<NavigationPropertyNameForeignKeyDiscoveryConvention>();
            modelBuilder.Conventions.Remove<StoreGeneratedIdentityKeyConvention>();

            modelBuilder.Properties<DateTime>()
                .Configure(c => c.HasColumnType("datetime"));
            modelBuilder.Properties<string>()
                .Configure(c => c.HasColumnType("varchar"));
            modelBuilder.Properties<string>()
                .Configure(c => c.HasMaxLength(500));
            modelBuilder.Properties()
                .Where(x => x.Name == "Id")
                .Configure(c => c.HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity));
            modelBuilder.Properties<DateTime>()
                .Where(x => x.Name == "FechaRegistro")
                .Configure(c => c.HasDatabaseGeneratedOption(DatabaseGeneratedOption.Computed));
            modelBuilder.HasDefaultSchema("dbo");

            modelBuilder.Ignore<ICollection>();

            modelBuilder.Entity<Organizacion>().HasKey(x => new {x.EmpresaId, x.PaisId});
        }
开发者ID:Code2Read,项目名称:PruebaConcepto,代码行数:25,代码来源:Contexto.cs

示例2: OnModelCreating

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
            modelBuilder.Conventions.Remove<OneToManyCascadeDeleteConvention>();
            modelBuilder.Conventions.Remove<ManyToManyCascadeDeleteConvention>();

             

            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 PersonMap());
            modelBuilder.Configurations.Add(new BreedMap());
            modelBuilder.Configurations.Add(new SpecieMap());
            modelBuilder.Configurations.Add(new AnimalMap());
            modelBuilder.Configurations.Add(new PhotoMap());

        }
开发者ID:williannelson,项目名称:Apra,代码行数:25,代码来源:ModelContext.cs

示例3: OnModelCreating

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            // Removendo a Pluralidade da criação das Tabelas. Exem.: Vez de ser "Produtoes" será "Produtor", que forma eu foi indicado. (deixa fiel)
            modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
            // Removendo a opção de Deletar em castata quando tiver uma relação de um para muitos. (Not Delete Cascade)
            modelBuilder.Conventions.Remove<OneToManyCascadeDeleteConvention>();
            // Removendo a opção de Deletar em castata, quanto tiver uma relação de muitos para muitos. (Not Delete Cascade)
            modelBuilder.Conventions.Remove<ManyToManyCascadeDeleteConvention>();

            // Abaixou estou indicando ao EntityFramework que toda Propriedade que estiver com o Nome + "Id" (Ex.: ClienteId) é uma propriedade que deve ser
            // setada como PK (Primary Key)
            modelBuilder.Properties().Where(p => p.Name == p.ReflectedType.Name + "Id").Configure(p => p.IsKey());

            // Abaixo estou indicando ao EntityFramework que toda Propriedade que for do tipo String, terá que ser criado no banco de dados como "varchar",
            // ao invés de "nvarchar" que é o default.
            modelBuilder.Properties<string>().Configure(p => p.HasColumnType("varchar"));

            // Abaixou ainda estou indicando ao EntityFramework que toda Propriedade que for do tipo String e não for setado nada, por default, vai ter
            // o tamanho Máximo de 100 caracter (varchar(100));
            modelBuilder.Properties<string>().Configure(p => p.HasMaxLength(100));

            // Desta forma, eu indico ao EntityFramework utilizar essas configurações adicionais, quando for construir as tabelas
            modelBuilder.Configurations.Add(new ClienteConfiguration());
            modelBuilder.Configurations.Add(new ProdutoConfiguration());
        }
开发者ID:MackMendes,项目名称:POC-DDD-Pires,代码行数:25,代码来源:ProjetoModeloContext.cs

示例4: OnModelCreating

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
            modelBuilder.Conventions.Remove<OneToManyCascadeDeleteConvention>();
            modelBuilder.Conventions.Remove<ManyToManyCascadeDeleteConvention>();

            modelBuilder.Properties()
                // ReSharper disable once PossibleNullReferenceException
                .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 ProjetoMap());
            modelBuilder.Configurations.Add(new RequisitoMap());
            modelBuilder.Configurations.Add(new CasoDeUsoMap());
            modelBuilder.Configurations.Add(new FluxoPrincipalMap());
            modelBuilder.Configurations.Add(new FluxoAlternativoMap());
            modelBuilder.Configurations.Add(new FluxoDeExcecaoMap());
            modelBuilder.Configurations.Add(new PassoMap());
            modelBuilder.Configurations.Add(new RegraDeNegocioMap());

            base.OnModelCreating(modelBuilder);
        }
开发者ID:marcosgneves,项目名称:Functional,代码行数:28,代码来源:FunctionalContext.cs

示例5: OnModelCreating

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();

            modelBuilder.Entity<Model>().HasMany(x => x.AvailableEngines)
                  .WithMany(x => x.AvailableIn)
                  .Map(x => x.MapLeftKey("ModelId").MapRightKey("EngineId").ToTable("ModelAvailableEngines"));

            modelBuilder.Entity<Manufacturer>().Property(x => x.Country).IsRequired().HasMaxLength(100);

            //Default Max Length to avoid VarChar Max
            modelBuilder.Properties()
                    .Where(property => property.PropertyType == typeof(string))
                    .Configure(config => config.HasMaxLength(100));

            //Default Strings to Non-Nullable
            modelBuilder.Properties()
                    .Where(property => property.PropertyType == typeof(string))
                    .Configure(config => config.IsRequired());

            //Add Custom Primary Key Convention
            modelBuilder.Properties()
                    .Where(prop => prop.Name.EndsWith("Key"))
                    .Configure(config => config.IsKey());

            modelBuilder.Entity<Option>().MapToStoredProcedures();

            base.OnModelCreating(modelBuilder);
        }
开发者ID:kburnell,项目名称:EfCodeFirstMagicUnicornAndBeyond,代码行数:29,代码来源:Demo1DataContext.cs

示例6: OnModelCreating

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            //convetions
            modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
            modelBuilder.Conventions.Remove<OneToManyCascadeDeleteConvention>();
            modelBuilder.Conventions.Remove<ManyToManyCascadeDeleteConvention>();

            //general custon Context properties
            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));

            //ModelConfiguration
            modelBuilder.Configurations.Add(new ModalidadeConfiguration());
            modelBuilder.Configurations.Add(new UnidadeCurricularConfiguration());
            modelBuilder.Configurations.Add(new CursoConfiguration());
            modelBuilder.Configurations.Add(new FaseConfiguration());
            modelBuilder.Configurations.Add(new GradeCurricularConfiguration());

            base.OnModelCreating(modelBuilder);
        }
开发者ID:DeNickXI,项目名称:ProjetoEnsalamento,代码行数:27,代码来源:ProjetoEnsalamentoContext.cs

示例7: OnModelCreating

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            // Conventions
            modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
            modelBuilder.Conventions.Remove<OneToManyCascadeDeleteConvention>();
            modelBuilder.Conventions.Remove<ManyToManyCascadeDeleteConvention>();

            //Custom Context Properties
            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(50));

            //modelBuilder.Properties<decimal>()
            //    .Configure(p => p.HasColumnType("money"));

            //model configuration
            modelBuilder.Configurations.Add(new ProdutosConfiguration());
            modelBuilder.Configurations.Add(new FornecedoresConfiguration());

            base.OnModelCreating(modelBuilder);
        }
开发者ID:Tmaturano,项目名称:PetSuite,代码行数:27,代码来源:PetSuiteContext.cs

示例8: OnModelCreating

        /// <summary>
        /// Defines the mapping between the application's entities and the database.
        /// </summary>
        /// <param name="modelBuilder">Model builder definition</param>
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Conventions.Remove<OneToManyCascadeDeleteConvention>();
            modelBuilder.Properties<Guid>().Where(x => x.Name == "ID").Configure(c =>
                c.IsKey()
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None)
                .HasColumnName("ID")
                .HasColumnOrder(0));

            modelBuilder.Properties<DateTime>().Where(x => x.Name == "CreatedDate").Configure(c =>
                c.HasColumnName("CreatedDate")
                .HasColumnOrder(1)
                .IsRequired());

            modelBuilder.Properties<DateTime>().Where(x => x.Name == "UpdatedDate").Configure(c =>
                c.HasColumnName("UpdatedDate")
                .HasColumnOrder(2)
                .IsRequired());

            modelBuilder.Configurations.Add(new AuthorMap());
            modelBuilder.Configurations.Add(new BlogMap());
            modelBuilder.Configurations.Add(new CommentMap());
            modelBuilder.Configurations.Add(new PostMap());
            modelBuilder.Configurations.Add(new LogMap());
            modelBuilder.Configurations.Add(new ErrorMap());

            base.OnModelCreating(modelBuilder);
        }
开发者ID:jdwittenauer,项目名称:blogit,代码行数:32,代码来源:BlogItContext.cs

示例9: OnModelCreating

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
            modelBuilder.Conventions.Remove<OneToManyCascadeDeleteConvention>();
            modelBuilder.Conventions.Remove<ManyToManyCascadeDeleteConvention>();

            //Redefine o padrão de reconhecimento do campo de Primary Key
            modelBuilder.Properties()
                .Where(p => p.Name == p.ReflectedType.Name + "Id")
                .Configure(p => p.IsKey());

            //Redifine padrões de tipos de campo do banco de dados
            modelBuilder.Properties<string>()
                .Configure(p => p.HasColumnType("varchar"));
            modelBuilder.Properties<string>()
                .Configure(p => p.HasMaxLength(100));

            //Chama configuração das entidades por Fluent API
            modelBuilder.Configurations.Add(new UsuarioConfig());
            modelBuilder.Configurations.Add(new AlunoConfig());
            modelBuilder.Configurations.Add(new ProfessorConfig());
            modelBuilder.Configurations.Add(new GrupoConfig());
            modelBuilder.Configurations.Add(new ProjetoConfig());
            modelBuilder.Configurations.Add(new CursoConfig());
            modelBuilder.Configurations.Add(new FaseConfig());
            modelBuilder.Configurations.Add(new AgendamentoConfig());
            modelBuilder.Configurations.Add(new TurmaConfig());
            modelBuilder.Configurations.Add(new SemestreConfig());
            modelBuilder.Configurations.Add(new ComentarioConfig());
        }
开发者ID:pelolisu,项目名称:SmartNet.OPEManager.Project,代码行数:30,代码来源:OPEModelContext.cs

示例10: OnModelCreating

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);
            var pluralization = DbConfiguration.DependencyResolver.GetService<IPluralizationService>();

            modelBuilder
                .Types()
                .Configure(x => {
                    var tableName = pluralization.Pluralize(x.ClrType.Name);
                    x.ToTable(tableName);
                    x.Property("Id").HasColumnName(x.ClrType.Name + "Id");
                });

            modelBuilder
                .Properties<int>()
                .Where(x => x.Name == "Id")
                .Configure(x => x
                    .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity)
                    .IsKey()
                );

            modelBuilder
                .Properties<string>()
                .Configure(x => x
                    .HasMaxLength(50)
                    .IsRequired()
                );
            modelBuilder.Configurations.AddFromAssembly(Assembly.GetExecutingAssembly());
        }
开发者ID:aritchie,项目名称:localization,代码行数:29,代码来源:LocalDbContext.cs

示例11: OnModelCreating

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
               modelBuilder.Conventions.Remove<OneToManyCascadeDeleteConvention>();
               modelBuilder.Conventions.Remove<ManyToManyCascadeDeleteConvention>();

               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));

               //CRM Configurations
               modelBuilder.Configurations.Add(new CustomerConfiguration());

               //SAP Configurations
               modelBuilder.Configurations.Add(new SapNoteConfiguration());
               modelBuilder.Configurations.Add(new SapSystemConfiguration());
               modelBuilder.Configurations.Add(new SapSUserConfiguration());
               modelBuilder.Configurations.Add(new LandscapeRoleConfiguration());
               modelBuilder.Configurations.Add(new AbapUserConfiguration());

               //Core Configurations
               modelBuilder.Configurations.Add(new SettingConfiguration());
        }
开发者ID:ebratz,项目名称:ESM,代码行数:29,代码来源:ESMContext.cs

示例12: OnModelCreating

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
            modelBuilder.Conventions.Remove<OneToManyCascadeDeleteConvention>();
            modelBuilder.Conventions.Remove<ManyToManyCascadeDeleteConvention>();

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

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

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


            modelBuilder.Configurations.Add(new ArquivoConfiguration());
            modelBuilder.Configurations.Add(new ContatoConfiguration());
            modelBuilder.Configurations.Add(new EnderecoConfiguration());
            modelBuilder.Configurations.Add(new PessoaConfiguration());
            modelBuilder.Configurations.Add(new PrioridadeConfiguration());
            modelBuilder.Configurations.Add(new ProjetoConfiguration());
            modelBuilder.Configurations.Add(new StatusConfiguration());
            modelBuilder.Configurations.Add(new TarefaConfiguration());
            modelBuilder.Configurations.Add(new TipoContatoConfiguration());
            modelBuilder.Configurations.Add(new UsuarioConfiguration());
        }
开发者ID:wagnermengue,项目名称:treinamento,代码行数:28,代码来源:TreinamentoContext.cs

示例13: OnModelCreating

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            // Conventions
            modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
            modelBuilder.Conventions.Remove<OneToManyCascadeDeleteConvention>();
            modelBuilder.Conventions.Remove<ManyToManyCascadeDeleteConvention>();

            // General Custom Context Properties
            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 TipoCursoConfiguration());
            modelBuilder.Configurations.Add(new CursoConfiguration());
            modelBuilder.Configurations.Add(new UsuarioConfiguration());
            modelBuilder.Configurations.Add(new AlunoConfiguration());
            modelBuilder.Configurations.Add(new AlunoHistoricoConfiguration());

            base.OnModelCreating(modelBuilder);
        }
开发者ID:DiegoONeves,项目名称:ControleUniversidade,代码行数:26,代码来源:UniversidadeContext.cs

示例14: setPropertyConfigurations

        private void setPropertyConfigurations(DbModelBuilder modelBuilder)
        {
            modelBuilder.Properties<string>()
                .Configure(p => p.HasColumnType("varchar"));

            modelBuilder.Properties<string>()
                .Configure(p => p.HasMaxLength(100));
        }
开发者ID:leocosta,项目名称:TicketStore,代码行数:8,代码来源:TicketStoreContext.cs

示例15: OnModelCreating

 protected override void OnModelCreating(DbModelBuilder modelBuilder)
 {
     modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
     modelBuilder.Conventions.Remove<OneToManyCascadeDeleteConvention>();
     modelBuilder.Conventions.Remove<ManyToManyCascadeDeleteConvention>();
     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));
 }
开发者ID:Rukasu2014,项目名称:MovimentoJovem,代码行数:9,代码来源:DataContext.cs


注:本文中的DbModelBuilder.Properties方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。