本文整理汇总了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));
}
示例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));
}
示例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);
}
});
}
示例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);
}
示例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);
}
}
示例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);
}
示例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());
}
示例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)));
}
示例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);
}
示例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);
}
示例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);
}
示例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");
});
}
示例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);
}
示例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);
}
示例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);
}