Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

Re-indexing an array

$
0
0

Hi guys,

     I'm working with some data that I'm currently getting back from my models as Dbset.ToList(). The data contains dates, similar to this:

{id: 1, date: 2017-03-01, attribute1: red, attribute2: 10 }, 

{id: 2, date: 2017-03-02, attribute1: green, attribute2: 20 }, 

{id: 3, date: 2017-03-03, attribute1: red, attribute2: 10 }, 

{id: 4, date: 2017-03-03, attribute1: green, attribute2: 5 }

I want to be able to access my 'attribute2' by referring to the date and 'attribute1' ..... so for example accessing x["2017-03-03"]["green"] should give 5.

Is there some nicely packaged, entity framework-esque way of transforming my list in this way? or should I do I just create it manually?

.... Ultimately, I just need to display the data in a table with all dates (including those without data) to be displayed as row headers and 'attribute1' to be displayed as column headers. Any suggestions on how I should approach this?


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>