-
-
Notifications
You must be signed in to change notification settings - Fork 231
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
[Question] How can I format a datetime (nullable) field value in select? #51
Comments
I don't know if it's possible to do in Select but you could do: var test1 = _context.Blogs.AsQueryable().Where("ModifyDate != null")
.Select("ModifyDate.Value.ToString(\"yyyy-MM-dd\")"); |
jotab123, thanks for your reply, but this is not my purpose, in your way, just find the not null value, but actually, I need to find all values, if it's null then will show empty or other thing, otherwise will format it and display |
Why not just execute the ToString method on a list instead of the queryable ? In that case you don't have issues with Linq-SQL. |
sorry, can you give me a sample how to do that? thanks! |
var list = _context.Blogs.Select("it.ModifyDate").ToDynamicList<DateTime>();
var result = list.Select(x => x ?? x.Value)).ToString("yyyy-MM-dd")).ToList(); |
but for my case, I need to generate a full dynamic query for get the result, and I don't want to convert to list at first, because I have a lot of data in the table, if it to list first then will get all data and the performance will be bad, that why I need to use IQueryable . and I know if I convert to list object then I can easy to use HasValue method in the query. |
Did you already try the Like
|
I want to format a nullable datetime value, how can I do that?
For example in Linq:
and I tried in dynamic Linq:
but I got the below error:
any ideas?
thanks!!
The text was updated successfully, but these errors were encountered: