0

I am working on an ASP.net page that also users ChartFX. I need to pull a row from a database table and then flip it so that all of the labels for the row are in a column and all of the data from the row is in a parallel column to the labels.

I would really like to do this using LINQ and then create a table in memory to store these values until I need to use them. What do you all suggest?

Jacob Huggart
  • 663
  • 2
  • 11
  • 30
  • I think this largely depends on what database you use and how do you access it, i.e. how does the row look like. Can you specify this info? – svick Jun 09 '10 at 18:43
  • Also, why do you want to store it in in-memory table, wouldn't `Dictionary<>` suffice? – svick Jun 09 '10 at 18:43
  • It's a SQL database accesed through a LINQ to SQL model in VS2008. Dictionary<> might do the trick, I just had not thought of that yet. – Jacob Huggart Jun 09 '10 at 18:57

1 Answers1

0

Using method I found at How would I get the column names from a Model LINQ?

var db = new DataContextType();
var members = db.Mapping.MappingSource
                        .GetModel(typeof(DataContextType))
                        .GetMetaType(typeof(TableType))
                        .DataMembers;

var row = …; // select the desired row

var namesAndValues = from member in members
                     select new
                     {
                         Name = member.Name,
                         Value = member.MemberAccessor.GetBoxedValue(row)
                     };
Community
  • 1
  • 1
svick
  • 236,525
  • 50
  • 385
  • 514
  • I found a way to get the column names. Once I have the column names I am just going to store everything in a datatable and then use pivot to move the columns to rows. Thanks for the reply. – Jacob Huggart Jun 09 '10 at 20:28