重新DBContext中OnModelCreating
protected
override
void OnModelCreating(ModelBuilder modelBuilder)
{
// 取基类=EntityBase
var entityTypes = Assembly.GetEntryAssembly().GetTypes()
.Where(type => !String.IsNullOrEmpty(type.Namespace))
.Where(type => type.GetTypeInfo().BaseType != null && type.GetTypeInfo().BaseType == typeof(EntityBase));
foreach ( var type in entityTypes)
{
modelBuilder.Model.GetOrAddEntityType(type);
}
base.OnModelCreating(modelBuilder);
}
{
// 取基类=EntityBase
var entityTypes = Assembly.GetEntryAssembly().GetTypes()
.Where(type => !String.IsNullOrEmpty(type.Namespace))
.Where(type => type.GetTypeInfo().BaseType != null && type.GetTypeInfo().BaseType == typeof(EntityBase));
foreach ( var type in entityTypes)
{
modelBuilder.Model.GetOrAddEntityType(type);
}
base.OnModelCreating(modelBuilder);
}
本文转自94cool博客园博客,原文链接:http://www.cnblogs.com/94cool/p/5849523.html,如需转载请自行联系原作者