An error occurs in the LINQ expression, that is, the method cannot convert the time into an expression. After constant thinking, the method finally understands the transcoding solution. I want to convert the background time object into a timestamp and then send it to the front-end for calling.
In this case, an error occurs:
Var comments = CommentSrv. GetListByCondition (t => t. ProductId = id // product comment
& Amp; t. Type = Type
& T. Content! = Null
& T. Content! = ""). OrderByDescending (t => t. CreateDate );
Var product = new {// display the product's comments (including time, product name, and comment)
Data. ID,
Data. Name,
Commnents = comments,
CreateDate = t. CreateDate. ToUnixTime () // time Conversion
};
Failure prompt:
LINQ to Entities does not recognize the method 'int64 ToUnixTime (System. DateTime) 'method, and this method cannot be
Translated into a store expression.
After modification:
Var comments = CommentSrv. GetListByCondition (t => t. ProductId = id // product comment
& Amp; t. Type = Type
& T. Content! = Null
& T. Content! = ""). OrderByDescending (t => t. CreateDate )).
Var product = new {// display the product's comments (including time, product name, and comment)
Data. ID,
Data. Name,
Commnents = comments,
CreateDate = t. CreateDate. ToUnixTime () // time conversion in milliseconds
};
Timestamp Conversion Result:
"CreateDate": 1336755430000