Monday, December 03, 2012 7:49 PM
I am trying to convert VB code (VS2010 targeting .Net 4.0) in a data visualization library which uses fluent Linq command syntax (Dim q = From myObj in myTable where ...) into Linq extension method syntax ( Dim q = myTable.where(...)) and am encountering a parsing error in Linq.Dynamic.vb when I attempt to use string expressions without parameter substitution.
Specifically, the following syntax seems to work:
Dim q = scTbl.Where("CompClass <> @0", "Land")But the following syntax, although patterned directly from Scott Gu's tutorial, does not:
Dim q = scTbl.Where("CompClass <> 'Land'")
The run-time exception I get is "DynamicLinq.ParseException was unhandled. Message=Character literal must contain exactly one character".
Is it not possible to use string where clauses without parameter substitution in Dynamic Linq?
Thanks for any help.
Monday, December 03, 2012 7:55 PMI am not a VB expert (any longer), but it seems that your single quotes are being misinterpreted. Try doubling them up like so:
Dim q = scTbl.Where("CompClass <> ''Land''")
"Premature optimization is the root of all evil." - Knuth
If I provoked thought, please click the green arrow
If I provoked Aha! please click Propose as Answer
- Marked As Answer by BGood Monday, December 03, 2012 8:15 PM
Monday, December 03, 2012 8:15 PM
Thanks Pieter. Good catch.
I changed the syntax to the following:
- Dim q = scTbl.Where("CompClass <> ""Land""")
And Dynamic Linq does not throw the parsing exception. It looks a little unwieldly with all those quotes, though.