Reputation: 11841
I am trying to write a WHERE clause for Entity Framework where Date contains a string from the input text, the input text could be mm or mm/dd or mm/dd/yyyy so I am trying write my WHere clause like so:
query.Where(p => (p.AccountingDate.Value.Month.ToString() + "/" + p.AccountingDate.Value.Day.ToString() + "/" + p.AccountingDate.Value.Year.ToString).Contains(gsStr))
but I get this error:
Operator '+' cannot be applied to operands of type 'string' and 'method group'
What is the best way to do this? I would really really love to use Contains instead of ==
Please Help!
Upvotes: 0
Views: 464
Reputation: 218798
Operator '+' cannot be applied to operands of type 'string' and 'method group'
You forgot to invoke the .ToString
method:
"/" + p.AccountingDate.Value.Year.ToString
should be:
"/" + p.AccountingDate.Value.Year.ToString()
The former resolves to the method itself (or "method group"), the latter resolves to the result of the method (which is a string).
Upvotes: 2