zuohuaijun / Admin.NET

🔥基于.NET 8(Furion)/SqlSugar实现的通用管理平台。整合最新技术,模块插件式开发,前后端分离,开箱即用。集成多租户、缓存、数据校验、鉴权、事件总线、动态API、通讯、远程请求、任务调度、gRPC等众多黑科技。代码简洁、易扩展,让开发更简单、更通用、更流行!
Apache License 2.0
191 stars 65 forks source link

dbProvider.CodeFirst.InitTables(entityType) 异常 #2

Closed kindao1 closed 3 months ago

kindao1 commented 12 months ago

生成表格时:使用的默认的数据库 Sqlite dbProvider.CodeFirst.InitTables(entityType); entityType为SysCodeGenConfig 时 报错了

System.Reflection.TargetInvocationException HResult=0x80131604 Message=Exception has been thrown by the target of an invocation. Source=System.Private.CoreLib StackTrace: 在 System.RuntimeMethodHandle.InvokeMethod(Object target, Span1& arguments, Signature sig, Boolean constructor, Boolean wrapExceptions) 在 System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) 在 Microsoft.Extensions.DependencyInjection.AppServiceCollectionExtensions.AddStartups(IServiceCollection services) 在 Microsoft.Extensions.DependencyInjection.AppServiceCollectionExtensions.AddApp(IServiceCollection services, Action1 configure) 在 Furion.InternalApp.<>c.b__5_1(WebHostBuilderContext hostContext, IServiceCollection services) 在 Microsoft.AspNetCore.Builder.ConfigureWebHostBuilder.ConfigureServices(Action2 configureServices) 在 Furion.InternalApp.ConfigureApplication(IWebHostBuilder builder, IHostBuilder hostBuilder) 在 Microsoft.AspNetCore.Builder.AppWebApplicationBuilderExtensions.Inject(WebApplicationBuilder webApplicationBuilder, Action2 configure) 在 System.Serve.Run(RunOptions options, String urls) 在 Program.

$(String[] args) 在 D:\Project\Admin.NET\Admin.NET\Admin.NET.Web.Entry\Program.cs 中: 第 10 行

此异常最初是在此调用堆栈中引发的: [外部代码]

内部异常 1: InvalidOperationException: Method may only be called on a Type for which Type.IsGenericParameter is true.

if (config.TableSettings.EnableInitTable) { var entityTypes = App.EffectiveTypes.Where(u => !u.IsInterface && !u.IsAbstract && u.IsClass && u.IsDefined(typeof(SugarTable), false)) .WhereIF(config.TableSettings.EnableIncreTable, u => u.IsDefined(typeof(IncreTableAttribute), false)).ToList();

if (config.ConfigId == SqlSugarConst.MainConfigId) // 默认库(有系统表特性、没有日志表和租户表特性)
    entityTypes = entityTypes.Where(u => u.GetCustomAttributes<SysTableAttribute>().Any() || (!u.GetCustomAttributes<LogTableAttribute>().Any() && !u.GetCustomAttributes<TenantAttribute>().Any())).ToList();
else if (config.ConfigId == SqlSugarConst.LogConfigId) // 日志库
    entityTypes = entityTypes.Where(u => u.GetCustomAttributes<LogTableAttribute>().Any()).ToList();
else
    entityTypes = entityTypes.Where(u => u.GetCustomAttribute<TenantAttribute>()?.configId.ToString() == config.ConfigId).ToList(); // 自定义的库

foreach (var entityType in entityTypes)
{
    if (entityType.GetCustomAttribute<SplitTableAttribute>() == null)
        dbProvider.CodeFirst.InitTables(entityType);
    else
        dbProvider.CodeFirst.SplitTables().InitTables(entityType);
}

}

zuohuaijun commented 3 months ago

请更新代码