假定有这样一个JSON
{ "appSettings": { "Keep": "1", "DefaultConnStr": "DeafultConnection" }, "ConnectionStrings": { "DeafultConnection": "Provider=mssql;", "ModuleConnection": "Provider=mssql;", "WeChatConnection": "Provider=mssql;", "MySqlConnection": "Provider=mysql;" }, "Logging": { "LogLevel": { "Default": "Information", "Microsoft": "Warning", "Microsoft.Hosting.Lifetime": "Information" } }, "AllowedHosts": "*" }
现在需要读取 ConnectionStrings 中所有节点 (且事先并不知道这个节点有几个)
在.NetFramework中知道如何操作 , 突然切换过来有点不知所措 .
var connectionStringsList = builder.Build().GetSection("ConnectionStrings").AsEnumerable(true);
foreach(var item in connectionStringsList )
item.key //DeafultConnection
item.value // Provider=mssql;
大神好厉害
没有用EF , 我们是要自己实现一个的 , 获取这个是为了缓存库和表结构