/// <summary> /// 加载数据库实体 /// </summary> /// <param name="modelBuilder"></param> private void LoadEntities(ModelBuilder modelBuilder) { AssemblyHelpers _assemblyHelper = new AssemblyHelpers(); var assemblys = _assemblyHelper.GetAssemblies(); foreach (var assembly in assemblys) { var types = assembly.GetTypes(); var assignTypeFrom = typeof(IBaseModel <>); var currentTypes = types.Where(t => t.IsClass && !t.IsGenericType && !t.IsAbstract && (assignTypeFrom.IsAssignableFrom(t) || (assignTypeFrom.IsGenericTypeDefinition && _assemblyHelper.DoesTypeImplementOpenGeneric(t, assignTypeFrom))) && !t.IsInterface); foreach (var type in currentTypes) { if (modelBuilder.Model.FindEntityType(type) == null) { modelBuilder.Model.AddEntityType(type); } } } }