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


C# DbModelBuilder.HasDefaultSchema方法代码示例

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


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

示例1: OnModelCreating

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);

            modelBuilder.Conventions.Remove<StoreGeneratedIdentityKeyConvention>();
            modelBuilder.Conventions.Remove<OneToManyCascadeDeleteConvention>();

            modelBuilder.HasDefaultSchema("UpCast");

            var customers = modelBuilder.Entity<Customer>().HasKey(customer => customer.Id);
            customers.Property(c => c.Id).HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

            var orders = modelBuilder.Entity<Order>().HasKey(order => order.Id);
            orders.Property(c => c.Id).HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

            var products = modelBuilder.Entity<Product>().HasKey(product => product.Id);
            products.Property(c => c.Id).HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

            var orderItems = modelBuilder.Entity<OrderItem>().HasKey(orderItem => orderItem.Id);
            orderItems.Property(c => c.Id).HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

            customers.HasMany(customer => customer.Orders).WithRequired(order => order.Customer);
            orders.HasMany(order => order.OrderItems).WithRequired(orderItem => orderItem.Order);
            products.HasMany(product => product.OrderItems).WithRequired(orderItem => orderItem.Product);
        }
开发者ID:yaoyel,项目名称:Finework,代码行数:25,代码来源:UpCastContext.cs

示例2: OnModelCreating

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.HasDefaultSchema("stepmap");

            modelBuilder.Entity<DataStore>().ToTable("DataStore");

            modelBuilder.Entity<Project>().ToTable("Project");
            modelBuilder.Entity<Project>()
                    .HasMany(e => e.FinishedSteps)
                    .WithRequired(e => e.Project)
                    .HasForeignKey(e => e.ProjectId);

            modelBuilder.Entity<Step>().ToTable("Step");
            modelBuilder.Entity<Step>()
                    .HasMany(e => e.SentReminders)
                    .WithRequired(e => e.Step)
                    .HasForeignKey(e => e.StepId);

            modelBuilder.Entity<Reminder>().ToTable("Reminder");
            
            modelBuilder.Entity<UserConfirmation>().ToTable("UserConfirmation");
            
            modelBuilder.Entity<User>().ToTable("User");
            modelBuilder.Entity<User>()
                    .HasMany(e => e.Projects)
                    .WithRequired(e => e.User)
                    .HasForeignKey(e => e.UserId);
        }
开发者ID:Kemyke,项目名称:StepMap.net,代码行数:28,代码来源:StepMapDbContext.cs

示例3: OnModelCreating

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.HasDefaultSchema("makerspace");

            modelBuilder.Entity<App_Areas>()
                .Property(e => e.title)
                .IsUnicode(false);

            modelBuilder.Entity<App_Areas>()
                .HasMany(e => e.App_User_Area_Memberships)
                .WithRequired(e => e.App_Areas)
                .HasForeignKey(e => e.area_id)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<App_Membership_Types>()
                .Property(e => e.title)
                .IsUnicode(false);

            modelBuilder.Entity<App_Membership_Types>()
                .HasMany(e => e.App_User_Area_Memberships)
                .WithRequired(e => e.App_Membership_Types)
                .HasForeignKey(e => e.membership_type_id)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<App_User_Profiles>()
                .Property(e => e.name)
                .IsUnicode(false);

            modelBuilder.Entity<App_User_Profiles>()
                .HasMany(e => e.App_User_Area_Memberships)
                .WithRequired(e => e.App_User_Profiles)
                .HasForeignKey(e => e.user_id)
                .WillCascadeOnDelete(false);
        }
开发者ID:kel-nelson,项目名称:MakerSpace,代码行数:34,代码来源:App_Model.cs

示例4: OnModelCreating

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Entity<Category>().HasKey(c => c.Id);

            modelBuilder.Entity<Product>().HasKey(p => p.Id);

            modelBuilder.Entity<Category>()
                .HasOptional(c => c.ParentCategory)
                .WithMany(c => c.SubCategories)
                .HasForeignKey(c => c.ParentCategoryId);

            modelBuilder.Entity<Product>()
                .HasRequired<Category>(p => p.Category)
                .WithMany(c => c.Products)
                .HasForeignKey(p => p.CategoryId);

            string schema = ServiceSettingsDictionary.GetSchemaName();
            if (!string.IsNullOrEmpty(schema))
            {
                modelBuilder.HasDefaultSchema(schema);
            }

            modelBuilder.Conventions.Add(
                new AttributeToColumnAnnotationConvention<TableColumnAttribute, string>(
                    "ServiceTableColumn", (property, attributes) => attributes.Single().ColumnType.ToString()));
        }
开发者ID:kirillg,项目名称:demo-xamarincrm,代码行数:26,代码来源:MobileServiceContext.cs

示例5: OnModelCreating

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);

            // Configure Default Schema
            modelBuilder.HasDefaultSchema("Institution");

            // Configure Tables
            modelBuilder.Entity<Course>().ToTable("Course");
            modelBuilder.Entity<Instructor>().ToTable("Instructor");
            modelBuilder.Entity<Student>().ToTable("Student");
            modelBuilder.Entity<ScheduledCourse>().ToTable("ScheduledClass");

            // Configure Primary Keys
            modelBuilder.Entity<Course>().HasKey<string>(course => course.CourseNumber);
            modelBuilder.Entity<Student>().HasKey<int>(student => student.StudentNumber);
            modelBuilder.Entity<ScheduledCourse>().HasKey(scheduledCourse =>
                new { scheduledCourse.CourseNumber, scheduledCourse.InstructorId });

            // Configure Many-to-Many Relationship
            modelBuilder.Entity<Student>()
                .HasMany<ScheduledCourse>(student => student.ScheduledCourses)
                .WithMany(scheduledCourse => scheduledCourse.Students)
                .Map(studentClass =>
                {
                    studentClass.MapLeftKey("StudentNumber");
                    studentClass.MapRightKey("CourseNumber", "InstructorId");
                    studentClass.ToTable("StudentClass");
                });
        }
开发者ID:MHeironimus,项目名称:EfCodeFirstSamples,代码行数:30,代码来源:SchoolDbContext.cs

示例6: 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

示例7: OnModelCreating

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            //

            modelBuilder.HasDefaultSchema("TDP");
            modelBuilder.Entity<Persona>().ToTable("Persona");
            modelBuilder.Entity<Telefono>().ToTable("Telefono");

            modelBuilder.Entity<Persona>()
                        .HasMany<Telefono>(p => p.Telefonos);
                       /* .WithRequired()
                        .Map(a => a.MapKey("Persona"))
                        .WillCascadeOnDelete(true);*/

            modelBuilder.Entity<Persona>().HasKey<int>(p => p.PersonaId);

            modelBuilder.Entity<Telefono>().HasKey<int>(t => t.TelefonoId);

            modelBuilder.Entity<Persona>()
                        .Property(p => p.PersonaId)
                        .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);

            modelBuilder.Entity<Telefono>()
                        .Property(t => t.TelefonoId)
                        .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);

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

示例8: OnModelCreating

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            // postgresql'de table'lar schema'larin altinda tanimlanir.
            // tercih edilen şemamız default olan "public"
            modelBuilder.HasDefaultSchema("public");

            // çoğul tablo ismi kullanmayı kaldırdık. 
            // misal User'a gidip Users tablosu değil User tablosu açacak.
            modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();

            // (many-to-many)
            modelBuilder.Entity<User>()
               // bir kullanicinin birden fazla ilgi alani olabilir, 
               .HasMany(e => e.Interests)
               // bir ilgi alaninin birden fazla kullanicisi olabilir
               .WithMany(e => e.Users)      
               .Map(
                   m =>
                   {
                       //'UserInterests' adinda bir tablo ac
                       m.ToTable("UserInterests");
                       // userid'yi UserId adli kolona koy
                       m.MapLeftKey("UserId");
                       // interestid'yi InterestId adli kolona koy 
                       m.MapRightKey("InterestId");    
                   }
                );
        }
开发者ID:zengfanlin,项目名称:PGCodeFirstMigrationExample,代码行数:28,代码来源:.dbcontext.cs

示例9: OnModelCreating

 protected override void OnModelCreating(DbModelBuilder modelBuilder)
 {
     modelBuilder.HasDefaultSchema("library");
     modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
     base.OnModelCreating(modelBuilder);
     //modelBuilder.Entity<FilePath>().HasOptional(p => p.Color).WithOptionalPrincipal();
 }
开发者ID:EMqqq,项目名称:AdminPanel,代码行数:7,代码来源:AdminPanelContext.cs

示例10: OnModelCreating

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

            base.OnModelCreating(modelBuilder);
        }
开发者ID:Lebda,项目名称:SciaDesignFormsWeb,代码行数:7,代码来源:SciaDesignFormsDb.cs

示例11: OnModelCreating

 protected override void OnModelCreating(DbModelBuilder modelBuilder)
 {
     if (Database.Connection.GetType() == typeof(Npgsql.NpgsqlConnection))
     {
         modelBuilder.HasDefaultSchema("public");
         modelBuilder.Conventions.Add<SnakeCaseConvention>();
     }
 }
开发者ID:jennings,项目名称:Causal,代码行数:8,代码来源:CausalContext.cs

示例12: OnModelCreating

 protected override void OnModelCreating(DbModelBuilder modelBuilder)
 {
     modelBuilder.HasDefaultSchema("std");
     modelBuilder.Conventions.Remove<OneToManyCascadeDeleteConvention>();
     modelBuilder.Conventions.Remove<ManyToManyCascadeDeleteConvention>();
     modelBuilder.Properties<DateTime>().Configure(c => c.HasColumnType("datetime2"));
     base.OnModelCreating(modelBuilder);
 }
开发者ID:asimshah,项目名称:apollo-web,代码行数:8,代码来源:MusicDatabase.cs

示例13: OnModelCreating

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.HasDefaultSchema("public"); // default scheme for postgresql

            modelBuilder.RegisterAllMappingFromCurrentAssembly();

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

示例14: BuildModel

 /// <summary>Builds the model defined in this class with the modelbuilder specified. Called from the generated DbContext</summary>
 /// <param name="modelBuilder">The model builder to build the model with.</param>
 public virtual void BuildModel(DbModelBuilder modelBuilder)
 {
     modelBuilder.HasDefaultSchema("dbo");
     MapApiDataSource(modelBuilder.Entity<ApiDataSource>());
     MapMovieCreditResult(modelBuilder.Entity<MovieCreditResult>());
     MapMovieNotFound(modelBuilder.Entity<MovieNotFound>());
     MapMovieResult(modelBuilder.Entity<MovieResult>());
 }
开发者ID:justinrobinson,项目名称:ODataTest,代码行数:10,代码来源:SqlExpressNovemberModelBuilder.cs

示例15: OnModelCreating

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

            // PostgreSQL uses the public schema by default - not dbo.
            modelBuilder.HasDefaultSchema("public");
            base.OnModelCreating(modelBuilder);
        }
开发者ID:RafaelSalguero,项目名称:DatabaseSkeleton,代码行数:9,代码来源:Db.cs


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