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


C# DbModelBuilder.Types方法代码示例

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


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

示例1: OnModelCreating

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Conventions.Add(
                new AttributeToColumnAnnotationConvention<TableColumnAttribute, string>(
                    "ServiceTableColumn", (property, attributes) => attributes.Single().ColumnType.ToString()));

            // The EntityFramework SQL Compact provider does not support the DateTimeOffset type
            modelBuilder.Types<TodoItem>().Configure(x => x.Ignore(prop => prop.CreatedAt));
            modelBuilder.Types<TodoItem>().Configure(x => x.Ignore(prop => prop.UpdatedAt));
        }
开发者ID:shrishrirang,项目名称:azure-mobile-apps-quickstarts,代码行数:10,代码来源:TryMobileAppsContext.cs

示例2: OnModelCreating

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            DbInterception.Add(new FilterInterceptor());

            modelBuilder.Conventions.Add<ForeignKeyNamingConvention>();

            modelBuilder.Types<Entity>()
                .Configure(t => 
                { 
                    t.Property(p => p.Id).HasColumnName(t.ClrType.Name + "Key");
                    t.Property(p => p.InternalId).HasColumnName(t.ClrType.Name + "Id").IsKey();
                    t.Property(p => p.Watermark).IsConcurrencyToken();

                    t.Ignore(p => p.Events);
                });

            modelBuilder.Types<TenantEntity>()
                .Configure(t =>
                {
                    t.Property(p => p.TenantId).HasColumnName("ClientId");
                });

            modelBuilder.Entity<Traveler>()
                .ToTable("Traveler")
                .HasOptional(t=> t.TravelerType);

            modelBuilder.Entity<TravelerType>()
                .ToTable("TravelerType");

            modelBuilder.Entity<Client>()
                .ToTable("Client");

            modelBuilder.Entity<Comment>()
                .ToTable("Comment");

            modelBuilder.Entity<TravelRequest>()
                .ToTable("TravelRequest")
                .HasMany(t => t.Travelers)
                    .WithMany()
                    .Map(m => m.MapLeftKey("TravelRequestId")
                        .MapRightKey("TravelerId")
                        .ToTable("TravelRequestTraveler"));

            modelBuilder.Entity<TravelRequest>()
                .HasMany(t => t.Comments)
                .WithRequired()
                .HasForeignKey(t => t.TravelRequestId);


            modelBuilder.Conventions.Add(
                FilterConvention.Create<IDeletable, bool>(DbContextFilterNames.ExcludeDeleted, (e, isDeleted) => e.IsDeleted == false));

            modelBuilder.Conventions.Add(
                FilterConvention.Create<ITenantEntity, long>(DbContextFilterNames.Tenant, (e, tenantId) => e.TenantId == tenantId));
        }
开发者ID:neekgreen,项目名称:EntityFrameworkConventions,代码行数:55,代码来源:LocalDbContext.cs

示例3: ConfigureEntityFrameworkProperties

        /// <summary>
        /// Configures protected EF Properties to be used, and the matching public properties to be ignored.
        /// </summary>
        /// <param name="modelBuilder">The model builder to use for configuration.</param>
        private static void ConfigureEntityFrameworkProperties(DbModelBuilder modelBuilder)
        {
            Contract.Requires<ArgumentNullException>(modelBuilder != null, "modelBuilder");

            modelBuilder
                .Types()
                .Configure(ec =>
                {
                    // if a property ends in EF, use that property (but column name is without EF)
                    // and ignore the same property without the EF
                    var propertyTwins =
                        from efpi in ec.ClrType.GetProperties(BindingFlags.Instance | BindingFlags.NonPublic)
                        where efpi.Name.EndsWith("EF", StringComparison.Ordinal)
                        join pi in ec.ClrType.GetProperties(BindingFlags.Instance | BindingFlags.Public) on efpi.Name equals pi.Name + "EF"
                        select new
                        {
                            EFProperty = efpi,
                            PublicProperty = pi
                        };

                    foreach (var propertyTwin in propertyTwins)
                    {
                        ec.Property(propertyTwin.EFProperty).HasColumnName(propertyTwin.PublicProperty.Name);
                        ec.Ignore(propertyTwin.PublicProperty);
                    }
                });
        }
开发者ID:Jork,项目名称:Billboard,代码行数:31,代码来源:DbContextModelConfiguration.cs

示例4: OnModelCreating

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Types().
                Configure(c => c.Ignore("IsDirty"));

            modelBuilder
                .Entity<MitchellClaimType>()
                .Property(p => p.ClaimNumber)
                .HasMaxLength(255);

            modelBuilder
                .Entity<MitchellClaimType>()
                .Property(t => t.ClaimNumber)
                .HasColumnAnnotation("Index", new IndexAnnotation(new IndexAttribute() { IsUnique = true }))
                .IsRequired();

            modelBuilder.Entity<MitchellClaimType>()
            .HasOptional<LossInfoType>(u => u.LossInfo)
            .WithRequired(c => c.Claim).Map(p => p.MapKey("ClaimId"))
            .WillCascadeOnDelete();

            modelBuilder
                .Entity<VehicleInfoType>()
                .Property(t => t.Mileage)
                .IsOptional();

            modelBuilder
               .Entity<VehicleInfoType>()
               .Property(t => t.LicPlateExpDate)
               .IsOptional();

            base.OnModelCreating(modelBuilder);
        }
开发者ID:tkalubi,项目名称:MitchellClaim,代码行数:33,代码来源:MitchellClaimContext.cs

示例5: OnModelCreating

		protected override void OnModelCreating(DbModelBuilder modelBuilder)
		{

			modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();

			// Use IDataObject.Guid as primary key
			modelBuilder.Types<IDataObject>().Configure(c =>
			{
				c.HasKey(e => e.Id);
				c.Property(p => p.Id)
					.HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity).IsRequired()
					.HasColumnAnnotation("Index", new IndexAnnotation(new IndexAttribute("LogicalId")));
			});

			var entityMethod = typeof(DbModelBuilder).GetMethod("Entity");
			var types = AppDomain.CurrentDomain
				.GetAssemblies()
				.Except(this.GetType().Assembly.ItemAsList())
				.SelectMany(s => s.GetTypes())
				.Where(p =>
					typeof(IData).IsAssignableFrom(p)
					&& !typeof(IDistributedDataObject).IsAssignableFrom(p)
					&& p.IsClass && !p.IsAbstract);

			foreach (var t in types)
			{
				entityMethod.MakeGenericMethod(t)
				  .Invoke(modelBuilder, new object[] { });
			}

		    if (OnModelCreatingAction != null)
		    {
                OnModelCreatingAction(modelBuilder);
		    }
		}
开发者ID:ochird,项目名称:Ractor.CLR,代码行数:35,代码来源:DynamicContexts.cs

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

示例7: OnModelCreating

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);
            var pluralization = DbConfiguration.DependencyResolver.GetService<IPluralizationService>();

            modelBuilder
                .Types()
                .Configure(x => {
                    var tableName = pluralization.Pluralize(x.ClrType.Name);
                    x.ToTable(tableName);
                    x.Property("Id").HasColumnName(x.ClrType.Name + "Id");
                });

            modelBuilder
                .Properties<int>()
                .Where(x => x.Name == "Id")
                .Configure(x => x
                    .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity)
                    .IsKey()
                );

            modelBuilder
                .Properties<string>()
                .Configure(x => x
                    .HasMaxLength(50)
                    .IsRequired()
                );
            modelBuilder.Configurations.AddFromAssembly(Assembly.GetExecutingAssembly());
        }
开发者ID:aritchie,项目名称:localization,代码行数:29,代码来源:LocalDbContext.cs

示例8: OnModelCreating

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Conventions.Remove<OneToManyCascadeDeleteConvention>();
            modelBuilder.Conventions.Remove<ManyToManyCascadeDeleteConvention>();

            modelBuilder.Types()
                        .Configure(t => t.ToTable(GetTableName(t.ClrType)));
        }
开发者ID:markashleybell,项目名称:StoreSpike,代码行数:8,代码来源:StoreContext.cs

示例9: OnModelCreating

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Configurations.Add(new YoyoMap());
            modelBuilder.Configurations.Add(new ColorwayMap());

            modelBuilder.Types().
                Configure(c => c.Ignore("IsDirty"));

            base.OnModelCreating(modelBuilder);
        }
开发者ID:lukas412,项目名称:MyYoyos,代码行数:10,代码来源:MyYoyosContext.cs

示例10: OnModelCreating

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Types().Configure(entity => entity.ToTable("glf." + entity.ClrType.Name));
            modelBuilder.Entity<User>().HasOptional(u => u.FacebookResource);
            modelBuilder.Entity<User>().HasOptional(u => u.GoogleResource);
            modelBuilder.Entity<FacebookResource>().HasRequired(r => r.User);
            modelBuilder.Entity<GoogleResource>().HasRequired(r => r.User);

            ModelCreating(modelBuilder);
        }
开发者ID:eziante,项目名称:GenericLoginFramework,代码行数:10,代码来源:GLFDbContext.cs

示例11: OnModelCreating

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Properties().Where(p => p.Name.Equals("Id")).Configure(p => p.IsKey().HasColumnName(TableColumnNameHelper.GetColumnNamePrependedByEntityName(p.ClrPropertyInfo)));

            modelBuilder.Properties().Where(p => p.Name.Equals("RowVersion")).Configure(p => p.IsRowVersion().HasColumnName("RowVersion"));

            modelBuilder.Types().Configure(t => t.ToTable(TableColumnNameHelper.GetTableName(t.ClrType)));
            modelBuilder.HasDefaultSchema(GetSchemaName());
            AddConfigurations(modelBuilder);
            base.OnModelCreating(modelBuilder);
        }
开发者ID:itssourabh22,项目名称:projectIGI,代码行数:11,代码来源:BaseDataContext.cs

示例12: OnModelCreating

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();

            modelBuilder.Types<TFSUsageLog>()
                .Configure(x =>
                {
                    x.Property(p => p.Id).IsKey().HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
                    x.Property(p => p.UserName).HasMaxLength(50);
                    x.Property(p => p.UserAgent).HasMaxLength(200);
                    x.Property(p => p.AccessDate).HasColumnType("DateTime");
                });
        }
开发者ID:devopsteamberlin,项目名称:TFSDatawarehouse,代码行数:13,代码来源:TFSUsersContext.cs

示例13: OnModelCreating

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.HasDefaultSchema("");

            modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
            modelBuilder.Types().Configure(c => c.ToTable(ToLowerCaseTableName(c.ClrType)));

            modelBuilder.Entity<ClubLokaal>()
                .HasRequired(c => c.Club)
                .WithMany(l => l.Lokalen)
                .HasForeignKey(x => x.ClubId);

            modelBuilder.Entity<ClubContact>()
                .HasRequired(c => c.Club)
                .WithMany(c => c.Contacten)
                .HasForeignKey(x => x.ClubId);
        }
开发者ID:TTCErembodegem,项目名称:TTC-React-Back,代码行数:17,代码来源:TtcDbContext.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<IdentifyingCodeInfo>()
                .HasKey(t => t.IdentifyingCodeId);

            modelBuilder.Entity<HotelOrderInfo>()
                .HasKey(t => t.id);

            modelBuilder.Entity<HotelUserInfo>()
                .HasKey(t => t.Id);

            modelBuilder.Entity<HotelAdminInfo>()
                .HasKey(t => t.Id);

            modelBuilder.Entity<HotelInfo>()
                .HasKey(t => t.id);
        }
开发者ID:jxiaox,项目名称:weixinpfnew,代码行数:19,代码来源:HotelDbContext.cs

示例15: OnModelCreating

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.HasDefaultSchema(schemaName);
            modelBuilder.Conventions.Add(new LowerCasePropertyNameConvention());

            modelBuilder.Types().Configure(configuration =>
            {
                string name = configuration.ClrType.Name.ToLower();
                configuration.ToTable(name);
            });

            modelBuilder.Properties().Configure(configuration =>
            {
                string name = configuration.ClrPropertyInfo.Name.ToLower();
                configuration.HasColumnName(name);
            });

            base.OnModelCreating(modelBuilder);
        }
开发者ID:affecto,项目名称:dotnet-IdentityManagement,代码行数:19,代码来源:PostgreDbContext.cs


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