本文整理汇总了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
}
示例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);
}
示例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
}
示例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");
}
示例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());
}
示例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
}
示例7: OnModelCreating
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<Feature>()
.HasMany(e => e.Feedback)
.WithRequired(e => e.Feature)
.WillCascadeOnDelete(false);
}
示例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);
}
示例9: OnModelCreating
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
modelBuilder.Configurations.Add(new JobInfoMap());
base.OnModelCreating(modelBuilder);
}
示例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);
}
示例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());
}
示例12: OnModelCreating
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Conventions.Add(new DateTimePrecisionAttributeConvention());
modelBuilder.Conventions.Add(new DecimalPrecisionAttributeConvention());
}
示例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);
}
示例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);
}
示例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