0

您好我正在尝试使用此组件: https ://www.nrecosite.com/pivot_data_library_net.aspx

我看到在这个项目中他们使用 sqlLite 作为连接字符串。

不幸的是,当我更改 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)"
                }

到这个连接字符串:

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”。请帮忙。

4

1 回答 1

0

查看官方文档,该文档解释了如何使用 PivotData SDK 加载预聚合数据:https ://www.nrecosite.com/pivotdata/load-pre-aggregated-data.aspx

简而言之,您的 SQL ... GROUP BY 查询应该返回GroupedSourceReader组件预期的列。在您的示例中,您指定了以下多维数据集配置:

  • 维度:“appname”、“dbname”、“db_path”
  • 聚合器:“计数”

并且您的 SQL 查询应返回以下列:

SELECT appname, dbname, db_path, COUNT(*) as cnt 
FROM [some_table] GROUP BY appname, dbname, db_path

换句话说,您应该在 GROUP BY 中指定用作维度的所有列,并使用 SQL 汇总函数计算聚合。

顺便说一句,如果您不想在数据库级别聚合数据,您可以使用 PivotData 类在 .NET 代码中指定简单的选择并执行聚合(参见 ToolkitSqlDbSource 示例)。

于 2017-04-27T10:11:10.140 回答