• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# DbModelBuilder类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: OnModelCreating

 protected override void OnModelCreating(DbModelBuilder modelBuilder)
 {
     modelBuilder.Configurations.Add(new Mapping.SexoMapping());
     modelBuilder.Configurations.Add(new Mapping.EstadoCivilMapping());
     modelBuilder.Configurations.Add(new Mapping.ContatoMapping());
     base.OnModelCreating(modelBuilder);
 }
开发者ID:ErickWendel,项目名称:Lgroup.DesignPatterns.DAO,代码行数:7,代码来源:Conexao.cs


示例17: OnModelCreating

 protected override void OnModelCreating(DbModelBuilder modelBuilder)
 {
     modelBuilder.Conventions.Remove<System.Data.Entity.ModelConfiguration.Conventions.PluralizingTableNameConvention>();
     modelBuilder.Entity<Instructor>().HasOptional(i => i.OfficeAssignment).WithRequired(o => o.Instructor);
     modelBuilder.Entity<Course>().HasMany(c => c.Instructors).WithMany(i => i.Courses).Map(t => t.MapLeftKey("CourseID").MapRightKey("InstructorID").ToTable("CourseInstructor"));
     modelBuilder.Entity<Department>().HasOptional(d => d.Administrator);
 }
开发者ID:hliang89,项目名称:WebWidgets,代码行数:7,代码来源:SchoolDBContext.cs


示例18: OnModelCreating

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

            modelBuilder.Entity<Dish>()
                .HasMany(e => e.DishesProducts)
                .WithRequired(e => e.Dish)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<Dish>()
                .HasMany(e => e.PersonEatStories)
                .WithRequired(e => e.Dish)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<Person>()
                .Property(e => e.PersonName)
                .IsUnicode(false);

            modelBuilder.Entity<Person>()
                .HasMany(e => e.PersonEatStories)
                .WithRequired(e => e.Person)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<Product>()
                .Property(e => e.ProductName)
                .IsUnicode(false);

            modelBuilder.Entity<Product>()
                .HasMany(e => e.DishesProducts)
                .WithRequired(e => e.Product)
                .WillCascadeOnDelete(false);
        }
开发者ID:zuuuiko,项目名称:Caloria,代码行数:34,代码来源:CalorieModel.cs


示例19: OnModelCreating

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

            modelBuilder.Entity<HistoryRow>().Property(m => m.MigrationId).HasMaxLength(100).IsRequired();
            modelBuilder.Entity<HistoryRow>().Property(m => m.ContextKey).HasMaxLength(200).IsRequired();
        }
开发者ID:liumeifu,项目名称:OSky,代码行数:7,代码来源:MySqlHistoryContext.cs


示例20: OnModelCreating

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Entity<Post>()
                .HasMany(e => e.Comments)
                .WithRequired(e => e.Post)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<Post>()
                .HasMany(e => e.Tags)
                .WithMany(e => e.Posts)
                .Map(m => m.ToTable("PostsTags").MapLeftKey("PostId").MapRightKey("TagId"));

            modelBuilder.Entity<User>()
                .Property(e => e.UserName)
                .IsUnicode(false);

            modelBuilder.Entity<User>()
                .HasMany(e => e.Comments)
                .WithOptional(e => e.User)
                .HasForeignKey(e => e.AuthorId);

            modelBuilder.Entity<User>()
                .HasMany(e => e.Posts)
                .WithOptional(e => e.User)
                .HasForeignKey(e => e.AuthorId);
        }
开发者ID:borko9696,项目名称:SoftwareUniversity,代码行数:26,代码来源:BlogDbContex.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# DbParameter类代码示例发布时间:2022-05-24
下一篇:
C# DbManager类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap