Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. LINQ
  4. Dynamic Grouping

Dynamic Grouping

Scheduled Pinned Locked Moved LINQ
linqquestioncsharpdatabase
2 Posts 2 Posters 3 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    tmp0
    wrote on last edited by
    #1

    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

    H 1 Reply Last reply
    0
    • T tmp0

      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

      H Offline
      H Offline
      Howard Richards
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups