c# - How to use properly linq to perform efficiently a conversion from a DataTable to a set of recursive objects? -


i'm working on software dealing tests, developping using visual studio 2008, c#3.5. tests saved sqlite database, , software intended process results.

well, there information table gathering general information tests following columns:

  • layeraname
  • layeraid
  • layerbname
  • layerbid
  • layercname
  • layercid
  • layerdname
  • layerdid
  • start: datetime indicate when result table has been created.
  • stop: datetime indicate when result table has been modified last time.
  • resulttablename: table name used displaying results in datagridview using virtualmode.

the layers discriminated using ids , btw, layer c, layers behaving containers gathering childlayers. last layer, "layerd" linked table in database.

public abstract class layer {     public string name { get; set; }     public int32 id { get; set; }     public datetime start { get; set; }     public datetime stop { get; set; } }  public class project: layer {     private int32 id { get; set; }     public dictionary<int32, layerb> { get; set; } }  public class layera : layer {     public project parent { get; set; }     public dictionary<int32, layerb> bs { get; set; } }  public class layerb : layer {     public layera parent { get; set; }     public dictionary<int32, layerc> cs { get; set; } }  public class layerc : layer {     public layerb parent { get; set; }     public dictionary<int32, layerb> ds { get; set; } }  public class layerd : layer {     public layerc parent { get; set; }     public string resulttablename { get; set; } } 
  • obviously if childlayer.start < childlayer.parent.start => childlayer.parent.start = childlayer.start.
  • the same kind of logic used stop attribute follows: if childlayer.stop > childlayer.parent.stop => childlayer.parent.stop = childlayer.stop.

anyway, fact have succeeded create objects according design above using giant loop running through datarows presents in information table described previously. made version using linq , datatable enumerable() both versions of code, me, dirty , hard maintain. difficulties come conversion table / datatable set of layer objects

so i'm wondering how improve this...

  • is there solution improve design?
  • any pattern use helping?
  • is there appropriate linqs filtering , creating dictionaries containing childlayers current schema of information table.

thanks.

so why not just

public class concretelayer: layer {     public layer parent { get; set; }     public dictionary<int32, layer> children{ get; set; } }  public class finallayer: layer {     public layer parent { get; set; }     public string resulttablename { get; set; } } 

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 -