EF cannot use time to convert string, and ef cannot convert string
Scenario:
The query condition must be time-formatted, for example, ToString ("yyyy-MM-dd;
In this case, use the following method:
Var q = from c in context. HasDateModels where c. UserDate. ToString ("yyyy-MM-dd"). Contains ("20") select c;
For query and use;
Tip: The method "System. String ToString (System. String)" is not recognized by LINQ to Entities. Therefore, this method cannot be converted to a storage expression.
That is, Linq to Entities does not support time String Conversion with Parameters
Solution:
The following method is applicable only when the data volume is small. We also recommend that you use this method. If there are other conditions, we recommend that you filter the data by using the following method;
Var q = from c in context. HasDateModels. AsEnumerable () where c. UserDate. ToString ("yyyy-MM-dd"). Contains ("20") select c;
Principle: Use AsEnumerable to convert the usage method to Linq to Object, and query the data to the memory before filtering.