0

Working in VB.NET and assuming it will work like C#. Clearly foolish.

dim moqValidationData = new DataTable()

moqValidationData.Columns.Add("TransactionItemID")
moqValidationData.Columns("TransactionItemID").dataType = GetType(Integer)
moqValidationData.Columns.Add("AdjustmentType")
moqValidationData.Columns("AdjustmentType").dataType = GetType(String)
moqValidationData.Columns.Add("DeliveryDate")
moqValidationData.Columns("DeliveryDate").dataType = GetType(Date)
moqValidationData.Columns.Add("AdjustmentAmount")
moqValidationData.Columns("AdjustmentAmount").dataType = GetType(Double)

moqValidationData.Rows.Add(1,"Set To Zero",Nothing,Nothing)
moqValidationData.Rows.Add(2,"Adjustment Value",New Date(2017,1,1),1)
moqValidationData.Rows.Add(2,"Adjustment Value",New Date(2017,1,2),2)
moqValidationData.Rows.Add(2,"Adjustment Value",New Date(2017,1,3),3)

dim raw = moqValidationData.Rows.Cast(Of DataRow)

Tried this

dim obj1 = 
  raw.GroupBy(Function (g) new With { .TiID = CInt(g("TransactionItemId")), g("AdjustmentType").ToString()}, 
              Function(key,grp) new With{ .Ti=key.TiID, .adj = key.Adj, .vals = grp.ToList() } ).

and this

dim obj2 = 
  raw.GroupBy(Function (g) new With { .TiID = CInt(g("TransactionItemId")), .Adj = g("AdjustmentType").ToString()}).
      Select(Function (s) new With {.Key = s.Key, .Vals =  s.ToList()}).ToList()

I believe obj1/2 should be lists of 2 items with '.vals' on each being a DataRow collection of 1 and 3. Instead I am always getting lists of four with a single 'DataRow' in each items '.vals' collection.

Based on things like:

  1. Why anonymous types Equals implementation compares fields?
  2. Group By Multiple Columns

what I expect appears to be correct. What am I missing?

Community
  • 1
  • 1
Kludge
  • 19
  • 1
  • 8

1 Answers1

0

For the record, adding keyword 'Key' looks like:

dim objs = raw.GroupBy(Function (g) new With { 
    Key.TiID = CInt(g("TransactionItemId")), 
    Key.Adj = g("AdjustmentType").ToString()}).
            Select(Function (s) new With {.Key = s.Key, .Vals =  s.ToList()}).ToList()
Kludge
  • 19
  • 1
  • 8