"entity framework 4 / linq: how to convert from datetime to string in a query?" Code Answer


tostring() is not supported in linq to entities - there is a list of function helpers as part of sqlfunctions but this doesn't support date to string conversion.

easiest would be to first project to an anonymous type within the query and then cast to an ienumerable by using asenumerable() - after that you can use tostring() because you are now using linq to objects for the remainder of the query expression (there's a lengthy article on this topic here).

   var results = products.select( p => new { a.id, a.modified })
                         .select(p => new productvm() 
                                { id = p.id, 
                                  modified = p.modified.tostring() 
By Srb1313711 on October 13 2022
Only authorized users can answer the Search term. Please sign in first, or register a free account.