您好我正在尝试使用此组件: https://www.nrecosite.com/pivot_data_library_net.aspx
我在这个项目中看到他们使用sqlLite作为connectionString。
不幸的是,当我更改connectionString时:
new SqlGroupByCube("northwind",
new PivotDataConfiguration() {
Dimensions = new[]{"CategoryName","OrderDate_year","OrderDate_month","ProductName","CompanyName","Country","Region","City"},
Aggregators = new[] {
new AggregatorFactoryConfiguration("Count",null),
new AggregatorFactoryConfiguration("Sum", new object[] { "LineTotal" }),
new AggregatorFactoryConfiguration("Average", new object[] { "Quantity" })
}
},
new System.Data.SQLite.SQLiteConnection("Data Source="+ System.Web.HttpContext.Current.Server.MapPath("~/App_Data/northwind.db") ),
@"
SELECT ProductName, CategoryName, CompanyName, Country, Region, City, OrderDate_year, OrderDate_month, COUNT(*) as cnt, SUM(LineTotal) as LineTotal_Sum, AVG(Quantity) as Quantity_Average FROM (
SELECT p.ProductName, c.CategoryName, CAST(strftime('%Y',o.OrderDate) as integer) as OrderDate_year,
CAST(strftime('%m', o.OrderDate) as integer) as OrderDate_month, cust.CompanyName, cust.Country,
cust.Region, cust.City, od.Quantity, CAST( (od.Quantity*od.UnitPrice) as REAL) as LineTotal
FROM [Order Details] od
LEFT JOIN [Orders] o ON (o.OrderID=od.OrderID)
LEFT JOIN [Products] p ON (p.ProductID=od.ProductID)
LEFT JOIN [Categories] c ON (c.CategoryID=p.CategoryID)
LEFT JOIN [Customers] cust ON (cust.CustomerID=o.CustomerID)
) t
GROUP BY ProductName, CategoryName, CompanyName, Country, Region, City
"
) {
Name = "Northwind DB Orders (example of SQL data source)"
}
到这个connectionString:
string connetionString = "Data Source=" + @"192.168.192.168\SqlServer" + ";
Initial Catalog=SomeDbName;User ID=Name;Password=SomePassword";
pvtRepository = new PivotRepository(
new ICube[] {
new SqlGroupByCube("SomeName",
new PivotDataConfiguration() {
Dimensions = new[]{ "appname", "dbname", "db_path"},
Aggregators = new[] {
new AggregatorFactoryConfiguration("Count",null),
}
},
new SqlConnection(connetionString),
@"SELECT TOP 1000 [some_column],[some_column1],[some_column2],[db_path]FROM [SomeDbName].[dbo].[some_table]"
)
{
Name = "My Data Test"
}
我无法在此行的SqlGroupByCube.cs中获取数据并失败:
var groupedPvtDataReader = new GroupedSourceReader(
dbCmdSource,
"cnt" // column name with rows count for each entry
);
try
{
var pvtDataFromGroupBy = groupedPvtDataReader.Read(PvtCfg, PvtDataFactory);
}
catch(Exception ex)
{
//somehandler..
}
在例外情况下,我只得到“cnt”。 请帮忙。
答案 0 :(得分:0)
查看解释如何使用PivotData SDK加载预聚合数据的官方文档:https://www.nrecosite.com/pivotdata/load-pre-aggregated-data.aspx
简而言之,您的SQL ... GROUP BY查询应返回GroupedSourceReader
组件所需的列。在您的示例中,您已指定以下多维数据集配置:
并且您的SQL查询应返回以下列:
SELECT appname, dbname, db_path, COUNT(*) as cnt
FROM [some_table] GROUP BY appname, dbname, db_path
换句话说,您应该指定在GROUP BY中用作维度的所有列,并使用SQL汇总函数计算聚合。
顺便说一句,如果您不想在数据库级别聚合数据,您可以使用PivotData类在.NET代码中指定简单的选择和执行聚合(请参阅ToolkitSqlDbSource示例)。