0

I've store data for each collecting parameter in ObservableCollection<DataValue> collection:

public sealed class DataValue: BaseModel
    {
        private int _id;

        public int ID
        {
            get { return _id; }
            set
            {
                _id = value;
                NotifyPropertyChanged("ID");
            }
        }
        private DateTime _timevalue;
        public DateTime TimeValue
        {
            get { return _timevalue; }
            set
            {
                _timevalue = value;
                NotifyPropertyChanged("TimeValue");
            }
        }

        private double _value;
        public double Value
        {
            get { return _value; }
            set
            {
                _value = value;
                NotifyPropertyChanged("Value");
            }
        }

        private string _name;

        public string Name
        {
            get { return _name; }
            set
            {
                _name = value;
                NotifyPropertyChanged("Name");
            }
        }
    }

From DB layer I've get similar data:

╔═══════════╦═════════════════════╦═══════════╦═════════╗
║    ID     ║         Date        ║  Value    ║  Name   ║
╠═══════════╬═════════════════════╬═══════════╬═════════╣
║    1      ║ 2019-11-17 20:00:00 ║  200.05   ║  Name1  ║
║    1      ║ 2019-11-17 20:03:00 ║  210.05   ║  Name1  ║
║    1      ║ 2019-11-17 20:06:00 ║  225.45   ║  Name1  ║
║   ...     ║          ...        ║   ...     ║   ...   ║
║    2      ║ 2019-11-17 20:00:00 ║   1500    ║  Name2  ║
║    2      ║ 2019-11-17 20:03:00 ║   1600    ║  Name2  ║
║    2      ║ 2019-11-17 20:06:00 ║   1550    ║  Name2  ║
║   ...     ║          ...        ║   ...     ║   ...   ║
║    3      ║ 2019-11-17 20:00:00 ║   0.105   ║  Name3  ║
║    3      ║ 2019-11-17 20:03:00 ║   0.267   ║  Name3  ║
║    3      ║ 2019-11-17 20:06:00 ║   0.560   ║  Name3  ║
║   ...     ║          ...        ║   ...     ║   ...   ║
╚═══════════╩═════════════════════╩═══════════╩═════════╝

And I want to transpose it with LINQ to view without any aggregation, only transform. I.e. I want each parameters name1, name2, name3 ... nameN turn to column with values, like this:

╔═════════════════════╦════════════╦════════════╦════════════╦═══════════╗
║         Date        ║    Name1   ║   Name2    ║   Name3    ║  Name[n]  ║
╠═════════════════════╬════════════╬════════════╬════════════╬═══════════╣
║ 2019-11-17 20:00:00 ║   200.05   ║   1500     ║   0.105    ║  xxx.xx   ║ 
║ 2019-11-17 20:03:00 ║   210.05   ║   1600     ║   0.267    ║  xxx.xx   ║    
║ 2019-11-17 20:06:00 ║   225.45   ║   1550     ║   0.560    ║  xxx.xx   ║
║         ...         ║    ...     ║    ...     ║    ...     ║   ...     ║      
╚═════════════════════╩════════════╩════════════╩════════════╩═══════════╝

Any ideas how to do this ?

amaranth
  • 979
  • 2
  • 22
  • 40
  • Does this your answer? [How to Convert Row to Column in Linq and SQL](https://stackoverflow.com/questions/17971921/how-to-convert-row-to-column-in-linq-and-sql) – Selim Yildiz Nov 19 '19 at 10:03
  • @SelimYıldız No, I'm have data in list ObservableCollection and count of columns to transpose may be different. – amaranth Nov 19 '19 at 10:07
  • Have you considered doing the pivot on the db side and then pulling in a datatable? Also, if the dataset is large, trying to manipulate this in memory could be a problem. – Kevin Cook Nov 19 '19 at 20:15
  • @KevinCook Yes, I'm making PIVOT in T-SQL with dynamic query for unknow columns - it was in another project. Now I'll try it in LINQ and WPF application. – amaranth Nov 19 '19 at 20:46

0 Answers0