Skip to content

[Question] How can I format a datetime (nullable) field value in select? #51

@winsonet

Description

@winsonet

I want to format a nullable datetime value, how can I do that?

For example in Linq:

var expected1 = _context.Blogs.Select(x =>
    (string)((DateTime)(x.ModifyDate ?? x.ModifyDate.Value)).ToString("yyyy-MM-dd")).ToArray();

and I tried in dynamic Linq:

var test1 = _context.Blogs.Select<string>(
    "(string)((datetime)(ModifyDate ?? ModifyDate.Value)).ToString(\"yyyy-MM-dd\")").ToArray();

but I got the below error:

System.NotSupportedException : LINQ to Entities does not recognize the method 'System.String ToString(System.String)' method, and this method cannot be translated into a store expression.

any ideas?

thanks!!

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions