本文介绍了实体框架将DateTime转换为字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
leaves = leaves.Where(s => s.Employee.Name.ToUpper().Contains(searchString.ToUpper())
|| s.StartDate.ToString().Contains(searchString));
这将导致错误...请帮助我,
This will leads to an error..please help me,
错误:LINQ to Entities不识别方法'System.String ToString()'方法,并且此方法不能转换为存储表达式..
Error: LINQ to Entities does not recognize the method 'System.String ToString()' method, and this method cannot be translated into a store expression..
推荐答案
对每种情况进行不同的
DateTime dateValue;
if (DateTime.TryParse(searchString, out dateValue))
{
leaves = leaves.Where(l => l.StartDate == dateValue);
}
else
{
leaves = leaves.Where(s => s.Employee.Name.ToUpper().Contains(searchString.ToUpper()));
}
这篇关于实体框架将DateTime转换为字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!