I have downloaded and implemented the extension methods made available in the LINQ Dynamic Query Library I found
here . Everything was going well until I attempted to pass the following string into the where clause
"CREATE_DATE > CAST(\"01/021/2013\" as System.DateTime)"
In return I get the error ...
System.Linq.Dynamic.ParseException: ')' or ',' expected
After hours of stepping through the code it appears that it chokes when it attempts to parse the argument list ( ParseArgumentList() ). It seems that as it parses the string it expects a CloseParen to appear after the second \" and before the "as" in the
string, suggesting that it does not support or recognize this CAST syntax. I have tried several other methods of casting to the DateTime but all fail in one way or another.
Am I writing the CAST expression incorrectly or is there another way of doing this in Linq to Entities? I have seen a couple of way of doing this in LINQ to Objects and/or LINQ to SQL but that did not work for LINQ to Entities.
@dahla - Thanks for the suggestion. This, however, results in a new error "Character literal must contain exactly one character " ... This is particularly confusing as the exception is thrown after the ParseStringLiteral() method strips the single
quotes out of the string, and then throws an error if they are no longer there (??) [System.Linq.Dynamic.ExpressionParser.ParseStringLiteral() line 980]
If still fails, you have to try to use DateTime.Parse(Your string), and thenuse ToString("mm/dd/yyyy") instead to have a try with.
Or just directly use DateTime.Parse(……)
Thanks for the response Decker. Sorry about that. The "021" was a typo in the post but not a factor in the code problem (I double-checked to be sure). The suggestion to use "DateTime.Parse()" is good although is not supported by LINQ To Entities!! Figures
...
LINQ to Entities does not recognize the method 'System.DateTime Parse(System.String)' method, and this method cannot be translated into a store expression.
Garyon
Member
4 Points
6 Posts
" ')' or ',' expected " : When using the LINQ Dynamic Query Library (LINQ to Entities)
Jan 30, 2013 08:44 PM|LINK
I have downloaded and implemented the extension methods made available in the LINQ Dynamic Query Library I found here . Everything was going well until I attempted to pass the following string into the where clause
"CREATE_DATE > CAST(\"01/021/2013\" as System.DateTime)"
In return I get the error ...
System.Linq.Dynamic.ParseException: ')' or ',' expected
After hours of stepping through the code it appears that it chokes when it attempts to parse the argument list ( ParseArgumentList() ). It seems that as it parses the string it expects a CloseParen to appear after the second \" and before the "as" in the string, suggesting that it does not support or recognize this CAST syntax. I have tried several other methods of casting to the DateTime but all fail in one way or another.
Am I writing the CAST expression incorrectly or is there another way of doing this in Linq to Entities? I have seen a couple of way of doing this in LINQ to Objects and/or LINQ to SQL but that did not work for LINQ to Entities.
dahla
Participant
1816 Points
369 Posts
Re: " ')' or ',' expected " : When using the LINQ Dynamic Query Library (LINQ to Entities)
Jan 31, 2013 12:57 AM|LINK
Try using ' instead of " around your date string
Garyon
Member
4 Points
6 Posts
Re: " ')' or ',' expected " : When using the LINQ Dynamic Query Library (LINQ to Entities)
Jan 31, 2013 02:14 PM|LINK
@dahla - Thanks for the suggestion. This, however, results in a new error "Character literal must contain exactly one character " ... This is particularly confusing as the exception is thrown after the ParseStringLiteral() method strips the single quotes out of the string, and then throws an error if they are no longer there (??) [System.Linq.Dynamic.ExpressionParser.ParseStringLiteral() line 980]
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: " ')' or ',' expected " : When using the LINQ Dynamic Query Library (LINQ to Entities)
Feb 01, 2013 12:42 AM|LINK
Please change from "021" to "21" and have a try.
If still fails, you have to try to use DateTime.Parse(Your string), and thenuse ToString("mm/dd/yyyy") instead to have a try with.
Or just directly use DateTime.Parse(……)
Garyon
Member
4 Points
6 Posts
Re: " ')' or ',' expected " : When using the LINQ Dynamic Query Library (LINQ to Entities)
Feb 01, 2013 11:13 PM|LINK
Thanks for the response Decker. Sorry about that. The "021" was a typo in the post but not a factor in the code problem (I double-checked to be sure). The suggestion to use "DateTime.Parse()" is good although is not supported by LINQ To Entities!! Figures ...
LINQ to Entities does not recognize the method 'System.DateTime Parse(System.String)' method, and this method cannot be translated into a store expression.
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: " ')' or ',' expected " : When using the LINQ Dynamic Query Library (LINQ to Entities)
Feb 02, 2013 12:42 AM|LINK
Hi again,
To be honest, not every LINQ can be converted to SQL standard statement.
So you have to use AsEnumerable() to convert from LINQ-TO-OBJECT and that should be OK.