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


C# DbModelBuilder类代码示例

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


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

示例1: OnModelCreating

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {

            modelBuilder.Conventions.Remove<IncludeMetadataConvention>();
            //#if CONFIGURATION

            //modelBuilder.Entity<Blog>().ToTable("InternalBlogs", "dbo");

            //modelBuilder.Entity<Blog>().HasKey(b => new { b.Id, b.Title });
            //modelBuilder.Entity<Blog>().Property(p => p.Title).HasColumnName("BlogTitle").IsMaxLength();
            //modelBuilder.Entity<Blog>().Property(p => p.DateCreated)
            //    .HasColumnName("CreatedDate")
            //    .HasColumnOrder(1)
            //    .HasColumnType("date");

            //modelBuilder.Entity<Blog>().Map(
            //    mca =>
            //    {
            //        mca.Properties(b => new { b.Id, b.Title, b.BloggerName });
            //        mca.ToTable("InternalBlogs");
            //    }).Map(
            //            mca =>
            //            {
            //                mca.Properties(b => new { b.DateCreated });
            //                mca.ToTable("BlogDetails");
            //            });


            //modelBuilder.ComplexType<BlogDetails>();

            // If Post does not have a BlogId property, this configuration is required
                // so that all posts are bound to one Blog
            modelBuilder.Entity<Post>().HasRequired(p => p.Blog);
            modelBuilder.Entity<Person>()
                    .Map<PowerUser>(m => m.Requires("Type").HasValue("PU"))
                    .Map <RegularUser>(m => m.Requires("Type").HasValue("RU"));

            // To support the unconventional foreign key FKBlogId in Post this configuration is required
            modelBuilder.Entity<Post>()
                .HasOptional(p => p.Blog)
                .WithMany(b => b.Posts)
                //.HasForeignKey(p => p.FKBlogId)
                ;

            modelBuilder.Entity<Post>()
                .HasMany(p => p.Tags)
                .WithMany(t => t.Posts)
                .Map(mc =>
                {
                    mc.ToTable("PostJoinTag");
                    mc.MapLeftKey("PostId");
                    mc.MapRightKey("TagId");
                });


            // Configuration with entity configuration
            //modelBuilder.Configurations.Add(new BlogConfiguration());
            //#endif

        }
开发者ID:cmfaustino,项目名称:PROMPT11-05-DataAccess.cmfaustino,代码行数:60,代码来源:BlogContext.cs

示例2: OnModelCreating

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder
                .Entity<Book>()
                .ToTable("Book", "bs")
                .HasKey(b => b.Id);

            modelBuilder
                .Entity<Book>()
                .HasRequired(b => b.Author);

            modelBuilder
                .Entity<Book>()
                .HasMany(b => b.Genres)
                .WithMany(g => g.Books)
                .Map(bg =>
                {
                    bg.MapLeftKey("BookId");
                    bg.MapRightKey("GenreId");
                    bg.ToTable("BooksGenres", "bs");
                });

            modelBuilder
                .Entity<Author>()
                .ToTable("Author", "bs")
                .HasKey(a => a.Id);

            modelBuilder
                .Entity<Genre>()
                .ToTable("Genre", "bs")
                .HasKey(g => g.Id);
        }
开发者ID:higtrollers,项目名称:BooAppRepository,代码行数:32,代码来源:BookAppContext.cs

示例3: OnModelCreating

       // public IDbSet<TalonAmount> TalonAmounts{ get; set; }
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);
            modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();

         //   modelBuilder.Entity<Employee>().H
        }
开发者ID:alinabelova,项目名称:MedicalClinic,代码行数:8,代码来源:Db.cs

示例4: Update_exceptions_should_be_wrapped_when_generating_sproc_bodies

        public void Update_exceptions_should_be_wrapped_when_generating_sproc_bodies()
        {
            var modelBuilder = new DbModelBuilder();

            var model1 = modelBuilder.Build(ProviderInfo);

            var context = new WorldContext_Invalid();

            var commandTreeGenerator
                = new ModificationCommandTreeGenerator(
                    context
                        .InternalContext
                        .CodeFirstModel
                        .CachedModelBuilder
                        .BuildDynamicUpdateModel(ProviderRegistry.Sql2008_ProviderInfo));

            Assert.Throws<InvalidOperationException>(
                () => new EdmModelDiffer()
                    .Diff(
                        model1.GetModel(),
                        context.GetModel(),
                        new Lazy<ModificationCommandTreeGenerator>(() => commandTreeGenerator),
                        new SqlServerMigrationSqlGenerator())
                    .OfType<CreateProcedureOperation>()
                    .ToList())
                .ValidateMessage("ErrorGeneratingCommandTree", "Thing_Insert", "Thing");
        }
开发者ID:,项目名称:,代码行数:27,代码来源:

示例5: OnModelCreating

 protected override void OnModelCreating(DbModelBuilder modelBuilder)
 {
     modelBuilder.Configurations.Add(new IdentificationTypeConfiguration());
     modelBuilder.Configurations.Add(new PersonConfiguration());
     modelBuilder.Configurations.Add(new GatePassConfiguration());
     modelBuilder.Configurations.Add(new RequestStatusConfiguration());
 }
开发者ID:Kingston-Wharves,项目名称:TestProjects,代码行数:7,代码来源:GatePassContext.cs

示例6: OnModelCreating

 protected override void OnModelCreating(DbModelBuilder modelBuilder)
 {
     base.OnModelCreating(modelBuilder);
     modelBuilder.Entity<Customer>().ToTable("tblCustomers");//table mapping
     modelBuilder.Entity<Order>().ToTable("tblOrders");
     modelBuilder.Entity<Customer>().Property(x => x.CustomerCode).HasColumnName("CustomerCode");//column mapping
 }
开发者ID:SharmaAtul,项目名称:MvcTest,代码行数:7,代码来源:CustomerDB.cs

示例7: OnModelCreating

 protected override void OnModelCreating(DbModelBuilder modelBuilder)
 {
     modelBuilder.Entity<Feature>()
         .HasMany(e => e.Feedback)
         .WithRequired(e => e.Feature)
         .WillCascadeOnDelete(false);
 }
开发者ID:jimtaylor1974,项目名称:ProductReviewApp,代码行数:7,代码来源:RoundtuitDbContext.cs

示例8: OnModelCreating

 protected override void OnModelCreating(DbModelBuilder modelBuilder)
 {
     modelBuilder.Entity<NumberForLinq>().HasKey(e => e.Id);
     modelBuilder.Entity<ProductForLinq>().HasKey(e => e.Id);
     modelBuilder.Entity<CustomerForLinq>().HasKey(e => e.Id);
     modelBuilder.Entity<OrderForLinq>().HasKey(e => e.Id);
 }
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:7,代码来源:SimpleModelForLinq.cs

示例9: OnModelCreating

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

            modelBuilder.Configurations.Add(new JobInfoMap());
            base.OnModelCreating(modelBuilder);
        }
开发者ID:dinglicoding,项目名称:LookingJob,代码行数:7,代码来源:DbContextBase.cs

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

示例11: OnModelCreating

 protected override void OnModelCreating(DbModelBuilder modelBuilder)
 {
   modelBuilder.Configurations.Add(new BettingPAndLMap());
   modelBuilder.Configurations.Add(new BookmakerMap());
   modelBuilder.Configurations.Add(new TournamentCouponURLMap());
   modelBuilder.Configurations.Add(new CompetitionCouponURLMap());
   modelBuilder.Configurations.Add(new CompetitionMap());
   modelBuilder.Configurations.Add(new TournamentMap());
   modelBuilder.Configurations.Add(new TournamentEventMap());
   modelBuilder.Configurations.Add(new ExternalSourceMap());
   modelBuilder.Configurations.Add(new FundMap());
   modelBuilder.Configurations.Add(new MatchCouponURLMap());
   modelBuilder.Configurations.Add(new MatchMap());
   modelBuilder.Configurations.Add(new MatchOutcomeOddMap());
   modelBuilder.Configurations.Add(new MatchOutcomeProbabilitiesInMatchMap());
   modelBuilder.Configurations.Add(new MatchOutcomeMap());
   modelBuilder.Configurations.Add(new ObservedOutcomeMap());
   modelBuilder.Configurations.Add(new ScoreOutcomeProbabilitiesInMatchMap());
   modelBuilder.Configurations.Add(new ScoreOutcomeMap());
   modelBuilder.Configurations.Add(new SportMap());
   modelBuilder.Configurations.Add(new SurfaceMap());
   modelBuilder.Configurations.Add(new TeamPlayerExternalSourceAliasMap());
   modelBuilder.Configurations.Add(new TeamsPlayerMap());
   modelBuilder.Configurations.Add(new TournamentExternalSourceAliasMap());
   modelBuilder.Configurations.Add(new BookmakerExternalSourceAliasMap());
   modelBuilder.Configurations.Add(new KeyValuePairMap());
   modelBuilder.Configurations.Add(new TennisPredictionStatMap());
   modelBuilder.Configurations.Add(new MissingBookmakerExternalSourceAliasMap());
   modelBuilder.Configurations.Add(new MissingTeamPlayerExternalSourceAliasMap());
   modelBuilder.Configurations.Add(new MissingTournamentCouponURLMap());
   modelBuilder.Configurations.Add(new OutcomeCommentMap());
 }
开发者ID:Double222,项目名称:Samurai,代码行数:32,代码来源:ValueSamuraiContext.cs

示例12: OnModelCreating

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

            modelBuilder.Conventions.Add(new DateTimePrecisionAttributeConvention());
            modelBuilder.Conventions.Add(new DecimalPrecisionAttributeConvention());
        }
开发者ID:richardlawley,项目名称:EntityFrameworkAttributeConfig,代码行数:7,代码来源:TestContext.cs

示例13: OnModelCreating

        /// <summary>
        /// This method is called when the model for a derived context has been initialized, but
        /// before the model has been locked down and used to initialize the context.  The default
        /// implementation of this method does nothing, but it can be overridden in a derived class
        /// such that the model can be further configured before it is locked down.
        /// </summary>
        /// <param name="modelBuilder">The builder that defines the model for the context being created.</param>
        /// <remarks>Typically, this method is called only once when the first instance of a derived context
        /// is created.  The model for that context is then cached and is for all further instances of
        /// the context in the app domain.  This caching can be disabled by setting the ModelCaching
        /// property on the given ModelBuidler, but note that this can seriously degrade performance.
        /// More control over caching is provided through use of the DbModelBuilder and DbContextFactory
        /// classes directly.</remarks>
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            //modelBuilder.Configurations.Add(new RaceMapping());
            modelBuilder.Configurations.Add(new CreatureMapping());

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

示例14: OnModelCreating

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Entity<WorkNC_Factory>()
                .Property(e => e.ImageFile)
                .IsUnicode(false);

            modelBuilder.Entity<WorkNC_WorkZone>()
                .Property(e => e.MachiningTimeTotal)
                .IsFixedLength();

            modelBuilder.Entity<WorkNC_WorkZone>()
                .Property(e => e.ImageFile)
                .IsUnicode(false);

            modelBuilder.Entity<WorkNC_WorkZoneDetail>()
                .Property(e => e.MachineTime)
                .IsFixedLength();

            modelBuilder.Entity<WorkNC_WorkZoneDetail>()
                .Property(e => e.ImageFile)
                .IsUnicode(false);

            modelBuilder.Entity<WorkNC_WorkZoneDetailProblem>()
                .Property(e => e.ImageFile)
                .IsUnicode(false);
        }
开发者ID:dtafe,项目名称:WorkNC,代码行数:26,代码来源:WorkNCDbContext.cs

示例15: OnModelCreating

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Entity<Movies>()
                .HasMany(e => e.Favorites)
                .WithRequired(e => e.Movies)
                .HasForeignKey(e => e.MovieId)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<Movies>()
                .HasMany(e => e.UserMovieMarks)
                .WithRequired(e => e.Movies)
                .HasForeignKey(e => e.IdMovie)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<Roles>()
                .HasMany(e => e.Users)
                .WithRequired(e => e.Roles)
                .HasForeignKey(e => e.Role)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<Users>()
                .HasMany(e => e.Favorites)
                .WithRequired(e => e.Users)
                .HasForeignKey(e => e.UserId)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<Users>()
                .HasMany(e => e.UserMovieMarks)
                .WithRequired(e => e.Users)
                .HasForeignKey(e => e.IdUser)
                .WillCascadeOnDelete(false);
        }
开发者ID:AlexanderChechet,项目名称:ASP.NET.AlexanderChechet.MovieCatalogue,代码行数:32,代码来源:MovieCatalogueContext.cs


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