Dynamic Grouping
-
Hello all, I'm using System.Linq.Dynamic (LINQ Dynamic Query Library) to perform dynamic grouping. The user will be presented with three combo boxes, and shall select a column from each combo box, and a grouping will be done based on his selection. As of now, I have:
public IQueryable GetTransactionsGroupBy(params string[] columns)
{
string cols = string.Join(",", columns);var trans = Transactions.GroupBy(string.Format("new ({0})", cols), "new (SalePrice, SaleCount)", null); return trans;
}
public void Test()
{
var trans = GetTransactionsGroupBy("BranchID", "CarID");foreach(var t in trans) //// do something with t
}
Inserting a break-point in the foreach, I found the type of "t" to be: System.Data.Linq.SqlClient.ObjectReaderCompiler.Group<dynamicclass1,> How can I access the attributes of this object? Regards, Naimi
-
Hello all, I'm using System.Linq.Dynamic (LINQ Dynamic Query Library) to perform dynamic grouping. The user will be presented with three combo boxes, and shall select a column from each combo box, and a grouping will be done based on his selection. As of now, I have:
public IQueryable GetTransactionsGroupBy(params string[] columns)
{
string cols = string.Join(",", columns);var trans = Transactions.GroupBy(string.Format("new ({0})", cols), "new (SalePrice, SaleCount)", null); return trans;
}
public void Test()
{
var trans = GetTransactionsGroupBy("BranchID", "CarID");foreach(var t in trans) //// do something with t
}
Inserting a break-point in the foreach, I found the type of "t" to be: System.Data.Linq.SqlClient.ObjectReaderCompiler.Group<dynamicclass1,> How can I access the attributes of this object? Regards, Naimi
Not an expert on the Dynamic Queries lib (although I have looked at it). I assume that "new (SalePrice, SaleCount)" is the result generator so I would assume that t is an anonymous type containing a .SalePrice and .SaleCount property - you might be able to read the values using reflection and PropertyInfo.
'Howard