c# - Referencing DataRows by column name in a LINQ query, then filter via mapping with another dataset -


i have excel sheet contains columns , list of column mappings.

list<mapping> _mapping 

mapping class contains 2 strings

public class mapping {     public string excelcolumn { get; set; } //the excel column name     public string mapto { get; set; } //the column in sql database maps } 

basically, i'm trying marry 2 data sets similar sql where [field1] in [field2] clause. i'm having 2 problems:

  • cannot apply [] indexing class
  • enumerablerowcollection contains no definition field

code:

var allactivity = getactivity();  using (datatable exceldata = getexceldataastable()) //get datatable representation of excel sheet {     var exceldatarows = exceldata.asenumerable();      //do each field mapped     foreach(mapping fieldmapping in _mapping)     {         var result = activity in allactivity //where clause contains errors                      activity[fieldmapping.mapto].contains(exceldatarows.field<string>(fieldmapping.excelcolumn))                      select activity;     } } 

here's getactivity(), returns ienumerable

private ienumerable<tradeactivity> getactivity() 

figured out...

first, need ability reference class property string name. add class

public object this[string propertyname] {     { return this.gettype().getproperty(propertyname).getvalue(this, null); }     set { this.gettype().getproperty(propertyname).setvalue(this, value, null); } } 

need isolate 1 of datasets:

var excelcolumn = exceldata.asenumerable().select(r => r[fieldmapping.excelcolumn]); 

then clause:

var result = activity in allactivity              excelcolumn.contains(activity[fieldmapping.mapto])              select activity; 

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -