Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search datetime using string #23

Open
jagadeesh1492 opened this issue Dec 19, 2017 · 4 comments
Open

Search datetime using string #23

jagadeesh1492 opened this issue Dec 19, 2017 · 4 comments

Comments

@jagadeesh1492
Copy link

jagadeesh1492 commented Dec 19, 2017

query.Search(p=>p.date).soundex("10")

search datetime

@ninjanye
Copy link
Owner

ninjanye commented Jan 5, 2018

Could you expand on what it is you are trying to achieve?

Have you tried, query.Search(p=>p.date.ToString()).Soundex("10")

@yzorg
Copy link

yzorg commented Jan 25, 2018

LINQ does not support null-coalescing operator, so this
is NOT possible: query.Search(p => p.ClosedDate?.ToString() ?? "");

which leads to a lot of duplicated code like this:
query.Search(p => p.ClosedDate == null ? "" : p.ClosedDate.ToString());

Not asking for the feature, but after reading @ninjanye's blog posts on the topic I haven't seen a single example with NULL DATETIME columns. So more of an FYI than a feature request.

@ninjanye
Copy link
Owner

ninjanye commented Feb 5, 2018

Hi @yzorg

Thanks for getting in touch, could you link me to the particular article you are referring to and I'll try and see if I can help clear things up

@P47K0
Copy link

P47K0 commented Mar 23, 2022

I also converted a DateTime to a string but how can you do a search on the full date or multiple parts of a date? I clould only manage to do a search on one part of the date, the year for example.
query.Search(x => x.TransactionDateTime.ToString().Containing("2022");

Searching on "2022-03" gives an empty collection (while there are records with a TransactionDateTime of march this year).
query.Search(x => x.TransactionDateTime.ToString().Containing("2022-03");

When I try to pass a format to the ToString method, I get a Linq error:
query.Search(x => x.TransactionDateTime.ToString("s").Containing("2022-03")

Error:
DbSet<Transaction>().Where(t => t.TransactionDateTime.ToString("s").Contains("2022-03"))' could not be translated. Additional information: Translation of method 'System.DateTime.ToString' failed. If this method can be mapped to your custom function, see https://go.microsoft.com/fwlink/?linkid=2132413 for more information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants