locked
DateTime Conversion Problem RRS feed

  • Question

  • hi.. 
    i m converting the column value ( datetime) in toshortdatestring() in linq to entity bt its gives error on runtime 
    "LINQ to Entities does not recognize the method 'System.String ToShortDateString()' method, and this method cannot be translated into a store expression."

    is there any solution for this ? 

    thanks
    SAAD
    Tuesday, March 9, 2010 8:53 AM

Answers

  • EF converts the linq expression tree into store specific sql and executes it on the store. So any method that is part of the Linq query is either converted to a store function/operation or results in an exception if we don't recognize the method( which you are seeing). The work around would be to call the method outside the linq query and use the string result in the linq query.

    Thanks
    Srikanth


    This posting is provided "AS IS" with no warranties, and confers no rights.
    Wednesday, March 10, 2010 7:27 AM

All replies

  • EF converts the linq expression tree into store specific sql and executes it on the store. So any method that is part of the Linq query is either converted to a store function/operation or results in an exception if we don't recognize the method( which you are seeing). The work around would be to call the method outside the linq query and use the string result in the linq query.

    Thanks
    Srikanth


    This posting is provided "AS IS" with no warranties, and confers no rights.
    Wednesday, March 10, 2010 7:27 AM
  • Just wanted to let you know there is a solution in EF4. You can either use SqlFunctions or EntityFunctions class to solve your problem

    EntityFunctions.TruncateTime(DateTime)

    SqlFunctions.DatePart(..)

     


    Zeeshan Hirani Entity Framework 4.0 Recipes by Apress
    http://weblogs.asp.net/zeeshanhirani
    Tuesday, August 17, 2010 4:23 PM