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


C# DbModelBuilder.Entity方法代码示例

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


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

示例1: OnModelCreating

 protected override void OnModelCreating(DbModelBuilder modelBuilder)
 {
     // base.OnModelCreating(modelBuilder);
     switch (DbFactory.InheritenceStrategy) {
         case InheritenceStrategy.TablePerConcreteClass:
             modelBuilder.Entity<User>().Map(x => {
                 x.MapInheritedProperties();
                 x.ToTable("User");
             });
             modelBuilder.Entity<Thing>().Map(x => {
                 x.MapInheritedProperties();
                 x.ToTable("Thing");
             });
             modelBuilder.Entity<Event>().Map(x => {
                 x.MapInheritedProperties();
                 x.ToTable("Event");
             });
             modelBuilder.Entity<Work>().Map(x => {
                 x.MapInheritedProperties();
                 x.ToTable("Work");
             });
             break;
         default:
             throw new NotImplementedException();
     }
 }
开发者ID:mrdrbob,项目名称:ef-vs-nh,代码行数:26,代码来源:EfContext.cs

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

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

示例4: OnModelCreating

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Entity<User>()
                .HasMany(u => u.Friends).WithMany()
                .Map(m =>
                {
                    m.MapLeftKey("UserId");
                    m.MapRightKey("FriendId");
                    m.ToTable("UserFriends");
                });

            modelBuilder.Entity<User>()
                .HasMany(u => u.ProductsBought)
                .WithOptional(p => p.Buyer)
                .Map(m =>
                {
                    m.MapKey("BuyerId");
                });

            modelBuilder.Entity<User>()
                .HasMany(u => u.ProductsSold)
                .WithRequired(p => p.Seller)
                .Map(m =>
                {
                    m.MapKey("SellerId");
                });

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

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

示例6: OnModelCreating

 protected override void OnModelCreating(DbModelBuilder modelBuilder)
 {
     modelBuilder.Entity<State>().Property(m => m.Id).HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);
     modelBuilder.Entity<Team>().Property(m => m.Id).HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);
     modelBuilder.Entity<Player>().Ignore(m => m.PhotoToUpload);
     //modelBuilder.Entity<Player>().HasKey(m => new { m.Id, m.TeamId });
 }
开发者ID:smichelotti,项目名称:AWSDemo-TeamPortal,代码行数:7,代码来源:TeamPortalWebContext.cs

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

示例8: OnModelCreating

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Entity<PointOfInterest>().HasKey(i => i.ID);
            modelBuilder.Entity<POIType>().HasKey(i => i.ID);

            modelBuilder.Entity<POIType>().HasMany(i => i.POIs).WithRequired(i => i.Type).HasForeignKey(i => i.TypeID);
        }
开发者ID:pavrsoft,项目名称:BallaratMinute,代码行数:7,代码来源:BallaratMinuteModel.cs

示例9: OnModelCreating

 protected override void OnModelCreating(DbModelBuilder modelBuilder)
 {
     base.OnModelCreating(modelBuilder);
     modelBuilder.Entity<FillUp>().Property(f => f.Volume).HasPrecision(18, 4);
     modelBuilder.Entity<FillUp>().Property(f => f.UnitCost).HasPrecision(18, 4);
     modelBuilder.Entity<FillUp>().Property(f => f.TotalCost).HasPrecision(18, 4);
 }
开发者ID:Tallness,项目名称:FillUps,代码行数:7,代码来源:FillUpContext.cs

示例10: Configuration

        public void Configuration(DbModelBuilder modelBuilder)
        {
            modelBuilder.Entity<PostCategoria>()
                .ToTable("blog_post_categoria");

            modelBuilder.Entity<PostCategoria>()
                .HasKey(k => k.id)
                .Property(p => p.id)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);

            modelBuilder.Entity<PostCategoria>()
                .Property(p => p.Nome)
                .HasColumnType(SqlDbType.VarChar.ToString())
                .HasMaxLength(64)
                .IsRequired();

            modelBuilder.Entity<PostCategoria>()
                .Property(p => p.URL)
                .HasColumnType(SqlDbType.VarChar.ToString())
                .HasMaxLength(64)
                .IsRequired();

            modelBuilder.Entity<PostCategoria>()
                .HasMany(m => m.PostSet)
                .WithRequired()
                .HasForeignKey(f => f.idCategoria);
        }
开发者ID:renebizelli,项目名称:listroman,代码行数:27,代码来源:PostCategoriaConfigurationDB.cs

示例11: OnModelCreating

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Entity<Citizenship>()
                .HasMany(e => e.Users)
                .WithRequired(e => e.Citizenship)
                .HasForeignKey(e => e.CitizenshipIdIndex)
                .WillCascadeOnDelete(false);

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

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

            modelBuilder.Entity<MartialStatus>()
                .HasMany(e => e.Users)
                .WithRequired(e => e.MartialStatus)
                .HasForeignKey(e => e.MartialStatusIdIndex)
                .WillCascadeOnDelete(false);
        }
开发者ID:AlexZhdanovskikh,项目名称:ADB,代码行数:26,代码来源:DbModel.cs

示例12: OnModelCreating

 protected override void OnModelCreating(DbModelBuilder modelBuilder)
 {
     modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
     modelBuilder.Entity<Follow>().HasRequired(c => c.UFollow).WithMany().WillCascadeOnDelete(false);
     modelBuilder.Entity<Follow>().HasRequired(c => c.User).WithMany().WillCascadeOnDelete(false);
     modelBuilder.Entity<Gab>().HasRequired(c => c.User).WithMany().WillCascadeOnDelete(false);
 }
开发者ID:JokerXM,项目名称:Gabbler-.NET-MVC,代码行数:7,代码来源:GabblerDBContext.cs

示例13: OnModelCreating

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Entity<Animal>().ToTable("Animals");
            modelBuilder.Entity<AnimalType>().ToTable("AnimalTypes");

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

示例14: OnModelCreating

 protected override void OnModelCreating(DbModelBuilder modelBuilder)
 {
     modelBuilder.Types().Configure(entity => entity.ToTable(entity.ClrType.Name));
     // Configure the primary key for the OfficeAssignment 
     modelBuilder.Entity<WeiXinAppInfo>().HasKey(t => t.id);
     modelBuilder.Entity<WeiXinUserInfo>().HasKey(t => t.openid);
 }
开发者ID:jxiaox,项目名称:weixinpf,代码行数:7,代码来源:WeiXinDbContext.cs

示例15: OnModelCreating

 protected override void OnModelCreating(DbModelBuilder modelBuilder)
 {
     modelBuilder.Entity<Company>().HasMany(p => p.Contacts).WithRequired().WillCascadeOnDelete(true);
     modelBuilder.Entity<CompanyContact>().HasMany(p => p.Infos).WithRequired().WillCascadeOnDelete(true);
     modelBuilder.Entity<Project>().HasMany(p => p.Stakeholders).WithMany();
     base.OnModelCreating(modelBuilder);
 }
开发者ID:sabbour,项目名称:GraphDiff,代码行数:7,代码来源:TestDbContext.cs


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