Click here to Skip to main content
15,884,099 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
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

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



Please Help!
Posted
Updated 31-Mar-20 21:11pm

You can use like below:

SQL
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.
 
Share this answer
 
v2
Comments
Vi(ky 28-Oct-13 6:08am    
n.modificationdate.Contains is not occuer
Sampath Lokuge 28-Oct-13 6:09am    
what do you mean by not occuer ?
Vi(ky 28-Oct-13 6:13am    
.Contains option is coming to use it when typing the code
Sampath Lokuge 28-Oct-13 6:17am    
I have updated. Plz check that.
Vi(ky 28-Oct-13 6:40am    
error: "The best overloaded method match 'string.Contains(string)' has some invalid arguments"
Check this sample application:

Entity Framework for Beginners[^]
 
Share this answer
 
v2
first of all your submitting datetime should include .Date Keyword it makes your time to 1200 or 0000000
like that
ent.Receiving_Date = dateTimePicker1.Value.Date;


In database it will look like that
2020-04-01 00:00:00.000

Now you are going to Search or filter the data on the base of date then you will also give .Date here with datetimePicker as given below ;

var dd=db.tbl_Doner.Where(x => x.Receiving_Date==dateTimePicker1.Value.Date).ToList();
dataGridView1.DataSource = dd;



I hope it will work
I have got it about half an hour before posting to you, after spending alot of time on it.During search I found above answers but not working in first approach of EF.so best of Luck
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900