Last post Sep 10, 2014 04:27 AM by PatriceSc
Sep 09, 2014 06:07 AM|akki83|LINK
I am trying to convert String Type Date column to DateTime format dd/MM/yyyy in LINQ Query from C# code,I am getting this error
"LINQ to Entities does not recognize the method 'System.DateTime ParseExact(System.String, System.String, System.IFormatProvider)' method, and this method cannot be translated into a store expression." Here is my piece of code
custQuery = custQuery.Where(c => DateTime.ParseExact(c.docDate, "dd/MM/yyyy", CultureInfo.InvariantCulture) >= date1);
if (date2 != null)
custQuery = custQuery.Where(c => DateTime.ParseExact(c.docDate, "dd/MM/yyyy", CultureInfo.InvariantCulture) <= date2);
In Above code date1 and date2 are type DateTime in format "dd/MM/yyyy" while column docDate in LINQ is type string
if it is possible to apply parse method in LINQ Query,then where i am doing mistake
If not possible to conversion of column type from LINQ query,then how i can easily convert column type as desire
I am a new for Entity framework and LINQ,Please help me with your best solution and suggestion
Sep 09, 2014 07:00 AM|PatriceSc|LINK
EF translates a C# expression to SQL so it does't support everything (especially if it doesn't have a simple and direct SQL side counterpart). You have to store c.docDate as a string?
Rather than "how i can easily convert column type as desire" the point would be rather to store data under the format that makes more sense so that you never have any conversion to do.
What have you done to have a docDate string column. Is this on purpose?
Sep 10, 2014 02:35 AM|akki83|LINK
I cannt change type of column because it has already more than thousand data,that will affect in database, if it was already as Datetime column then i dont need to convert it from LINQ,.
It means In my situation there is no other solution rather than change column type in table,
docDate is accepting Date format dd/MM/yyyy in data table
Sep 10, 2014 03:23 AM|George Hua - MSFT|LINK
Welcome to MSDN forum.
Please refer threads below to solve this issue:
Conversion error in Entity Framework
big issue in converting string to datetime using linq-to-entities
Sep 10, 2014 04:27 AM|PatriceSc|LINK
For now it seems the easiest solution is to get data client side and then only to perform the conversion (which could be a performance problem). Would have to check if later EF versions allows for something less ugly (but anyway for example indexing this
column will be likely less efficient). Do you use code first or db first?
I would still strongly suggest to fix this issue once for all rather than to keep it and have to workaround this problem everytime you'll use this column.