c# - 错误 : No overload for method "ToString" takes 1 arguments

标签 c# linq

我正在尝试按特定顺序格式化日期

Time = DateTime.Parse(p.Time.ToString("dd-MM-yyyy HH:mm:ss"))

Time 的数据类型是DateTime

但是我收到了这个错误:

No overload for method "ToString" takes 1 arguments.

p 是我从中获取时间的表的对象。

  List<ProductImageMapWrapper> lstpm = new List<ProductImageMapWrapper>();
  lstpm = _db.ProductImageMaps.Where(i => i.ClientId == null && i.BrandId == null).Select(p => new ProductImageMapWrapper
  {
  Time= // Problem here
  }

现在,我尝试这样使用它

Time = DateTime.Parse(string.Format("{dd-MM-yyyy HH:mm:ss}", p.Time))

但是我得到了这个错误:

LINQ to Entities does not recognize the method System.DateTime Parse(System.String) method, and this method cannot be translated into a store expression.

最佳答案

String Time = Convert.ToDateTime(p.Time).ToString("dd-MM-yyyy HH:mm:ss");

关于c# - 错误 : No overload for method "ToString" takes 1 arguments,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21347353/

相关文章:

c# - 在 linq 中,为什么后续调用 IEnumerable.Intersect 的速度要快得多

c# - 从 azure 应用程序发送电子邮件时为 "The remote certificate is invalid according to the validation procedure"

C#:用于插入到 sql server 的 C# 中的日期格式

c# - 将 XAML 样式转换为代码隐藏样式?

c# - 抽象类和接口(interface)的区别

visual-studio-2008 - Visual Studio 2008 是否有一个插件可以让您在监 window 口中使用 Linq?

c# - 将命令行参数传递给使用 DotNetZip 创建的 SFX

LinQ 查询用于选择单行中的多个数据

c# - 在 LinqToSql 中是否有更短的方法将属性解析为 Int(或任何其他原语)

.net - 在SQL Server和.NET代码+ LINQ之间处理非常大的字符串