本文整理汇总了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);
}
示例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);
}
示例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);
}
示例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()));
}
示例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");
});
}
示例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});
}
示例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);
}
示例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");
}
);
}
示例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();
}
示例10: OnModelCreating
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
modelBuilder.HasDefaultSchema("sciaDesignForms");
base.OnModelCreating(modelBuilder);
}
示例11: OnModelCreating
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
if (Database.Connection.GetType() == typeof(Npgsql.NpgsqlConnection))
{
modelBuilder.HasDefaultSchema("public");
modelBuilder.Conventions.Add<SnakeCaseConvention>();
}
}
示例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);
}
示例13: OnModelCreating
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.HasDefaultSchema("public"); // default scheme for postgresql
modelBuilder.RegisterAllMappingFromCurrentAssembly();
base.OnModelCreating(modelBuilder);
}
示例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>());
}
示例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);
}