I don't think I can actually add a field (column) to an existing IEnumerable. But what I want is a new IEnumerable that is derived from an existing IEnumerable with a calculated field. The pseudocode in WebMatrix using Web Pages looks like:
var db = Database.Open("LOS");
var ie = db.Query(sqlAssignments);
// make a new ie2 that has an extra field
// ??? ie2 <=== ie with new field c = ie.a + ie.b
var grid = new WebGrid( ie2, extra parameters );
I know how to do this looping through all the rows in ie. But I'm hoping there's something more elegant.
How about:
var ie2 = ie.Select(x => new { x.Foo, x.Bar, Sum = x.Abc + x.Def });
var grid = new WebGrid(ie2);
You can do this using Select
. Try this:
ie2 = ie.Select( e => new { IE = e, NewParam = e.X+e.Y });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With