c# - Populate a LINQ table in code? -


question: want populate linq table code, not database.

is possible ?

system.data.linq.table<question> myquestions = new system.data.linq.table<question>(); 

then like:

myquestions.rows.add(aquestion); 

just populate regular datatable , can use linq

using system; using system.data;  namespace consoleapplication10 {   class program   {     static void main(string[] args)     {       var dt = new datatable();       dt.columns.add("id", typeof(int));       dt.columns.add("project name", typeof(string));       dt.columns.add("project date", typeof(datetime));        (int = 0; < 10; i++)       {         var row = dt.newrow();         row.itemarray = new object[] { i, "title-" + i.tostring(), datetime.now.adddays(i * -1) };         dt.rows.add(row);       }        var pp = p in dt.asenumerable()                (int)p["id"] > 2                select p;        foreach (var row in pp)       {         console.writeline(row["id"] + "\t" + row["project name"] + "\t" + row["project date"]);        }        console.readline();     }   } } 

in code above can see how use linq filter out records datatable. you'll need add system.data.datasetextensions assembly references

ienumerables readonly can't way you're asking, i've presented correct way.


Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -