Thanks so much ... " I can't see the forest for the trees".
Webmatrix compiler immediately happy. All concatenation working as advertised.
Dallas
StringBuilder(), Probably not a great choice for test data.
I will keep your performance note for the future.
"500,000 records and concatenating a string from the value of each record: performance may well become an iissue here as hundreds of thousands of redundant string objects are created in memoery. In scenarios involving anything more than one or two concatenations,
the StringBuilder class should be used to ensure that no performance hit occurs on your web site."
Lydford, "Webmatrix ... ", Page 61, "Concatenation and StringBuilder".
var s = "some string";
s += " some more string";
s += " and some more string";
s += " and even more string";
etc...
The more common recommendations are that 5 or 6 of these should be the trigger for moving across to a StringBuilder. "Anything more than one" concatenation is way too low in my opinion.
DMT20601
Member
86 Points
197 Posts
IEnumerable cannot resolve field name.
Jan 27, 2013 09:49 PM|LINK
I'm working with Webmatrix and the Starter Site.
I populated a var (dumptable) with db.query(Select ......)
Grabbed result with grid1 = webGrid(dumptable)
in the markup displayed the grid with @grid1.GetHtml() , worked fine.
Need to walk the var (dumptable) to pull some data.
Employed a FOREACH method.
Iteration cannot recognize fields names within the receiving variable (dumptable).
'System.Collections.Generic.IEnumerable<dynamic>' does not contain a definition for 'DealValue' and no extension method 'DealValue'
Line 59: @foreach (var looper in dumptable) Line 60: { Line 61: <p>@dumptable.DealValue.ToString() </p> <!-- datatype Money-->Line 62: Line 63: dealno.Append("M");This should work.
Thanks
Dallas in Maryland.
var grid1 = new WebGrid(dumptable); StringBuilder dealno = new StringBuilder(""); StringBuilder voucher = new StringBuilder(""); var oneUp = 1; } <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8" /> <title></title> </head> <body> <p style="font-size: 19pt">Table: Dealpool</p> <p style="font-size: 12pt">Current Date: @DateTime.Now.ToString()</p> <p>Display tool WebGrid()</p> <p>Page: _lksdeals/zWork/Table list/07 Dealpool.cshtml</p> <p>Sorted by: DealpoolId </p> @grid1.GetHtml() <hr> <hr> @foreach (var looper in dumptable) { <p>@dumptable.DealValue.ToString() </p> <!-- datatype Money--> dealno.Append("M"); dealno.Append("????"); dealno.Append("-D"); dealno.Append(@dumptable.DealValue.ToString()); voucher.Append(dealno); voucher.Append("-C"); voucher.Append(oneUp.ToString()); oneUp ++; <p>DealNo: @dealno </p> <p>Voucher: @voucher</p> } </body> </html>Mikesdotnett...
All-Star
154818 Points
19853 Posts
Moderator
MVP
Re: IEnumerable cannot resolve field name.
Jan 28, 2013 05:02 AM|LINK
Individual records containing fields are in the variable looper, not dumptable (which represents a collection of records):
@foreach (var looper in dumptable){ <p>@looper.DealValue.ToString() </p> //etc }Also, you don't need StringBuilders for simple concatenation there. They add unnecessary overhead
@foreach (var looper in dumptable) { <p>@looper.DealValue</p> oneUp ++; <p>@("DealNo: M???-D" + looper.DealValue)</p> <p>@("Voucher: dealno-C"+ oneUp)</p> }Beginning ASP.NET Web Pages with WebMatrix | My Site | Twitter
DMT20601
Member
86 Points
197 Posts
Re: IEnumerable cannot resolve field name.
Jan 28, 2013 10:51 AM|LINK
Thanks so much ... " I can't see the forest for the trees".
Webmatrix compiler immediately happy. All concatenation working as advertised.
Dallas
StringBuilder(), Probably not a great choice for test data.
I will keep your performance note for the future.
"500,000 records and concatenating a string from the value of each record: performance may well become an iissue here as hundreds of thousands of redundant string objects are created in memoery. In scenarios involving anything more than one or two concatenations, the StringBuilder class should be used to ensure that no performance hit occurs on your web site."
Lydford, "Webmatrix ... ", Page 61, "Concatenation and StringBuilder".
Mikesdotnett...
All-Star
154818 Points
19853 Posts
Moderator
MVP
Re: IEnumerable cannot resolve field name.
Jan 28, 2013 12:02 PM|LINK
StringBuilders should be used instead of e.g.
var s = "some string";
s += " some more string";
s += " and some more string";
s += " and even more string";
etc...
The more common recommendations are that 5 or 6 of these should be the trigger for moving across to a StringBuilder. "Anything more than one" concatenation is way too low in my opinion.
Beginning ASP.NET Web Pages with WebMatrix | My Site | Twitter