0

I'm implementing a simple search. Right now, I can search through the posts using the terms in string array Split but I want to search the date aswell. So, I added an array of datetime. The problem I'm having is I only want to search the Date part of datetime, and ignore Time. Whenever I search, I get an error at d.Date.

 IEnumerable<Post> posts = from p in post_repository.Posts 
                           from s in split 
                           from d in Date
                           where (p.Title.Contains(s) || p.ContactPhone.Contains(s) || p.Content.Contains(s) || p.Author.Contains(s) || p.ContactEmail.Contains(s)|| **p.EndDate.Date.Equals(d.Date)**) && p.Deleted == false && p.Publish == true 
                           select p;

Error Message:

The specified type member 'Date' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.


Exception Details: System.NotSupportedException: The specified type member 'Date' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported.

I've been stuck at this for a while, can anyone figure out what I'm doing wrong? All the dates are initialized, so there is nothing null and everything other than date works. If I remove d.Date or EndDate.Date, there is no error but I dont get the desired result. Thanks in Advance.

Edit 1:

string[] split = query.Split(breakpoints);
DateTime[] arrayOfDateTimes = Datify(split);

The Declaration might seem really stupid. Datify is a function I wrote which returns an array of DateTime which works properly cause I went through it step by step looking at the local variables.

private readonly char[] breakpoints = {'.', ',', ' ', ':', '\t' };

Query is the search, its a string.

3
  • Can you split apart what you think your query is doing? And giving us a declaration of what split and Date are would help too. As is, those second and third from expressions look wrong. Commented Nov 9, 2011 at 22:05
  • DateTime: 10/10/2010 12:36:...., Date would be 10/10/2010 part of datetime. I'll try to split it apart and write how it goes. Commented Nov 9, 2011 at 22:17
  • @IAbstractDownvoteFactory Cause of you comment I finally figured it out. Instead of Date, I used Day, Month and Year. Commented Nov 10, 2011 at 0:21

1 Answer 1

1

Use the class EntityFunction for trimming the time portion.

using System.Data.Objects;

EntityFunctions.TruncateTime(EndDate)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.