Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/entity-framework/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#使用linq将字符串搜索到datetime表列中_C#_Entity Framework_Linq - Fatal编程技术网

C#使用linq将字符串搜索到datetime表列中

C#使用linq将字符串搜索到datetime表列中,c#,entity-framework,linq,C#,Entity Framework,Linq,搜索字符串没有将数据搜索到datetime,比如datetime tostring返回“04/10/2020 02:05:41 PM”,因此,如果搜索字符串为04/10或10/2020或2020,它也应该返回所有匹配的行,如果搜索字符串为“04/10/2020”它应该返回所有匹配的行看起来您应该分别比较月份和年份x=>x.datetime.Month==2&&x.datetime.Year==2020这个字符串是什么意思?现在是2020年2月,是2020年的第二周吗?如果是的话,什么才算是第一周

搜索字符串没有将数据搜索到datetime,比如datetime tostring返回“04/10/2020 02:05:41 PM”,因此,如果搜索字符串为04/10或10/2020或2020,它也应该返回所有匹配的行,如果搜索字符串为“04/10/2020”它应该返回所有匹配的行

看起来您应该分别比较月份和年份
x=>x.datetime.Month==2&&x.datetime.Year==2020
这个字符串是什么意思?现在是2020年2月,是2020年的第二周吗?如果是的话,什么才算是第一周?假设文本搜索对您的工作很重要,请注意DateTime。ToString()的格式不一定是您期望的格式,比如月份和日期的前导零。。设置字符串的格式(例如:x.datetime.ToString(“dd/MM/yyyy”)…)这是否回答了您的问题?即使您自己编写SQL,这样的查询也是有问题的——我不认为EF能够生成一条SQL语句,而这条SQL语句不会完全是一种暴行。
using(model1 db = new model1())
{
string textsearch="02/2020";
db.table.where(x=>x.datetime.tostring().contain(textsearch);
}

// its not matching result with testsearch keys 

data = CustomMethods.OrderByField(addb.AppSettings
.Where(x => x.Name.Contains(searchString)
|| x.Value.Contains(searchString)
|| x.FriendlyName.Contains(searchString)
|| x.Description.Contains(searchString)
|| x.UpdatedBy.Contains(searchString)
|| x.TimeStamp.ToString().Contains(searchString))
.OrderBy(x => x.ID).Skip(skip).Take(pageSize), 
sortColumn, true);