protected override void OnModelCreating(ModelBuilder builder) { var type = GetType(); IEntityTypeConfiguraFinder finder = new EntityTypeConfiguraFinder(); var entityList = finder.FinderAll().ToList(); List <IEntityTypeRegiest> list = entityList.Select(type => Activator.CreateInstance(type) as IEntityTypeRegiest).ToList(); var data = list.Where(x => x.DbContextType == type).ToList(); foreach (IEntityTypeRegiest regist in data) { builder.Entity(regist.EntityType); } RegistConfiguration(builder); base.OnModelCreating(builder); }
/// <summary> /// 初始化数据库实体上下文 /// </summary> public static void InitEngityDbContext() { IEntityTypeConfiguraFinder finder = new EntityTypeConfiguraFinder(); var entityList = finder.FinderAll().ToList(); List <IEntityTypeRegiest> list = entityList.Select(type => Activator.CreateInstance(type) as IEntityTypeRegiest).ToList(); var result = list.GroupBy(x => x.DbContextType).ToList(); foreach (IGrouping <Type, IEntityTypeRegiest> item in result) { List <IEntityTypeRegiest> f = new List <IEntityTypeRegiest>(); if (diclist.ContainsKey(item.Key)) { var temp = diclist[item.Key]; temp.AddRange(item.ToList()); } else { diclist.TryAdd(item.Key, item.ToList()); } } }