Adding a new record to an IQueryable variable
Recently working on one of my application using Linq, I need to fill the datagridview with selected rows and columns which i can get from querying a list of objects using Linq. Now for every result i need to add an additional static record to the grid view. for this i need to have this record as a last record for my selected IQueryable variable from LINQ result. Let me show you through example what I said till now…
Ex:
1.var varresult = from r in lstobject select new { COLUMN1 = r.Title, COLUMN2 = r.Price };
2.
3.DataGridView1.datasource = varresult ;
4.
5.DataGridView1.databind();
Now I need to add a new static record (i.e.., new{COLUMN1=”Discount Price”, COLUMN2=10}) to the existing varresult object…
1.varresult = varresult.ToList().Union(new[] { new{COLUMN1=”Discount Price”, COLUMN2=10}});
2.
3.DataGridView1.datasource = varresult ;
4.
5.DataGridView1.databind();
thats it Now a last record will be what you want… Please note that the variables and there types should be same as result object had.
Hope this Helps u…
Happy Coding http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif?m=1129645325g