.net - how to convert a datatable to List<long,List<keyvaluepair<string,string>>> in C# -


i have datatable 3 columns says, id, name , value.

i want convert datatable list<long,list<keyvaluepair<string,string>>>.

the trick id foreign ket table. have repeatative values.

i want in c#.

thanks in advance.


no, not dictionaly.....actualy have 2 classes says, definded as....

public class runparameters     {         public long runid { get; set; }         public list<workflowparameter<string>> workflowparameters { get; set; }          public runparameters()         {             workflowparameters = new list<workflowparameter<string>>();         }     }   public struct workflowparameter<t>     {         public string parametername         { get; set; }         public t parametervalue         { get; set; }     } 

i want convert datable list.

i cannot use dictionary since want serialize list send across network....

group items in query id , project each item group keyvaluepair:

(from r in table.asenumerable()  group r r.field<long>("id") g  select g.select(i => new keyvaluepair<string, string>(                       i.field<string>("name"), i.field<string>("value"))          .tolist()).tolist() 

or method syntax:

 table.asenumerable()       .groupby(r => r.field<long>("id"))       .select(g => g.select(r => new keyvaluepair<string, string>(                           r.field<string>("name"), r.field<string>("value"))                     .tolist())       .tolist()  

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -