【发布时间】:2014-10-01 17:00:56
【问题描述】:
我必须以MMM dd,YYYY 格式显示日期。
var performancereviews = from pr in db.PerformanceReviews
.Include(a => a.ReviewedByEmployee)
select new PerformanceReviewsDTO
{
ReviewDate=pr.ReviewDate.ToString("MMM dd,yyyy"),
EmployeeName=pr.ReviewedByEmployee.Name,
JobTitle=pr.ReviewedByEmployee.JobTitle,
ReviewerComments=pr.CommentsByReviewer,
EmployeeComments=pr.CommentsByEmployee
};
这是我收到的错误消息
ExceptionMessage:LINQ to Entities 无法识别方法“System.String ToString(System.String)”方法,并且此方法无法转换为存储表达式。 异常类型: System.NotSupportedException
当我在pr.ReviewDate 上应用ToString 时出现错误。
请用适当的解决方案指导我如何做到这一点。我知道在普通的 C# 编码中有几个可用的选项,但在 Linq 中我们怎么做。
【问题讨论】:
-
一般显示格式化是在display逻辑中执行的,而不是在查询数据的时候。
PerformanceReviewsDTO.ReviewDate的类型是什么?这段代码给你什么错误? -
@David 我知道类型如果存储字符串类型值,那么它肯定应该是字符串,它是字符串这里是错误异常消息:LINQ to Entities 无法识别方法'System.String ToString( System.String)' 方法,并且此方法不能转换为存储表达式。异常类型:System.NotSupportedException
-
为什么有人投反对票,请不要忘记在投反对票时给 cmets。
标签: c# linq entity-framework linq-to-entities