使用实体框架按日期执行搜索 [英] Perform search by Date using entity framework

查看:76
本文介绍了使用实体框架按日期执行搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在Entity框架中进行搜索查询。我的表项目有'Id','ProjectName','Description'和modificationdate等。我想在'ProjecName','Description'和modificationdate上执行搜索。我成功地在'ProjectName'和' '描述',但我不知道如何按日期执行搜索



 var found = 来自 n   context.Project 
其中 n.projectName。包含(SearchKey)|| n.description。包含(SearchKey)
选择 n;







请帮助!

解决方案

您可以使用如下:



 var found = 来自 n  in  context.Project 
其中​​ n.projectName。包含( SearchKey)|| n.description。包含(SearchKey)|| n.modificationdate.ToShortDateString()。包含(EntityFunctions.TruncateTime(SearchKey))
选择 n;





我希望这会对你有所帮助。


检查这个示例应用程序:



实体框架初学者 [ ^ ]

I try to make search query in Entity framework. I have table Project with 'Id', 'ProjectName', 'Description' and "modificationdate" etc. I want to perform search on 'ProjecName', 'Description' and "modificationdate". I successfully perform search on 'ProjectName' & 'Description' but i don't know how perform search by date

var found = from n in context.Project
                            where n.projectName.Contains(SearchKey) ||                                                               n.description.Contains(SearchKey) 
                        select n;




Please Help!

解决方案

You can use like below:

var found = from n in context.Project
                            where n.projectName.Contains(SearchKey) ||                                                               n.description.Contains(SearchKey) || n.modificationdate.ToShortDateString().Contains(EntityFunctions.TruncateTime(SearchKey))
                        select n;



I hope this will help to you.


Check this sample application:

Entity Framework for Beginners[^]


这篇关于使用实体框架按日期执行搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆