c# - populating a DataTable with ADO .NET entity model -


i'm developping windows form application ado .net entity data model. have datatable dt = new datatable, how can populate datatable data base using databaseetities?

here query:

     data in db.sources       data.idtheme==idtheme       select data.url; 

you can create extension this, add on query:

public static datatable todatatable<t>(this list<t> items) {     var tb = new datatable(typeof(t).name);      propertyinfo[] props = typeof(t).getproperties(bindingflags.public | bindingflags.instance);      foreach(var prop in props)     {         tb.columns.add(prop.name, prop.propertytype);     }      foreach (var item in items)     {         var values = new object[props.length];         (var i=0; i<props.length; i++)         {             values[i] = props[i].getvalue(item, null);         }         tb.rows.add(values);     }      return tb; } 

your query this:

var newdatatable = (from data in db.sources                     data.idtheme == idtheme                     select data.url).todatatable(); 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -