本文整理汇总了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();
}
}
示例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();
}
示例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);
}
示例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);
}
示例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);
}
示例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 });
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例13: OnModelCreating
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<Animal>().ToTable("Animals");
modelBuilder.Entity<AnimalType>().ToTable("AnimalTypes");
base.OnModelCreating(modelBuilder);
}
示例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);
}
示例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);
}