locked
" ')' or ',' expected " : When using the LINQ Dynamic Query Library (LINQ to Entities) RRS feed

  • Question

  • User-383979169 posted

    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.

     

     

    Wednesday, January 30, 2013 4:44 PM

Answers

  • User3866881 posted

    The suggestion to use "DateTime.Parse()" is good although is not supported by LINQ To Entities!!

    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.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, February 1, 2013 8:42 PM

All replies

  • User1546878023 posted

    Try using ' instead of " around your date string

    Wednesday, January 30, 2013 8:57 PM
  • User-383979169 posted

    @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]

    Thursday, January 31, 2013 10:14 AM
  • User3866881 posted

    01/021/2013

    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(……)

    Thursday, January 31, 2013 8:42 PM
  • User-383979169 posted

    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(……)

    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.

    Friday, February 1, 2013 7:13 PM
  • User3866881 posted

    The suggestion to use "DateTime.Parse()" is good although is not supported by LINQ To Entities!!

    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.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, February 1, 2013 8:42 PM