C# Nreco数据透视表Mvc
嗨,我正在尝试使用此组件: 我看到在这个项目中,他们使用sqlLite来连接字符串 不幸的是,当我更改connectionString时:C# Nreco数据透视表Mvc,c#,asp.net,asp.net-mvc,asp.net-mvc-4,nreco,C#,Asp.net,Asp.net Mvc,Asp.net Mvc 4,Nreco,嗨,我正在尝试使用此组件: 我看到在这个项目中,他们使用sqlLite来连接字符串 不幸的是,当我更改connectionString时: new SqlGroupByCube("northwind", new PivotDataConfiguration() { Dimensions = new[]{"CategoryName","OrderDate_year","OrderDate_month","P
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”。
请提供帮助。请查看解释如何使用PivotData SDK加载预聚合数据的官方文档: 简而言之,您的SQL。。。GROUPBY查询应返回
GroupedSourceReader
组件所需的列。在您的示例中,指定了以下多维数据集配置:
- 维度:“appname”、“dbname”、“db_路径”
- 聚合器:“计数”
SELECT appname, dbname, db_path, COUNT(*) as cnt
FROM [some_table] GROUP BY appname, dbname, db_path
换句话说,您应该指定GROUPBY中用作维度的所有列,并使用SQL summary函数计算聚合
顺便说一句,如果您不想在数据库级别聚合数据,您可以使用PivotData类在.NET代码中指定简单的选择并执行聚合(请参见ToolkitSqlDbSource示例)