【问题标题】:linq with nullable datetime带有可为空日期时间的 linq
【发布时间】:2012-01-01 15:50:41
【问题描述】:

我正在对包含可空日期时间的表运行 linq-to-sql 查询,如下所示:

 var Output = from s in ....
              select new MyModel() 
              {
                  TheCloseDate = s.TheCloseDate.DateTime.Value
              }

但是,变量TheCloseDate 永远不会被填充。变量的 MyModel 定义是:

public Nullable<DateTime> TheCloseDate { get; set; }

我在这里做错了什么?

感谢您的建议。

【问题讨论】:

  • 你能详细说明TheCloseDate / TheCloseDate.DateTime 吗?
  • @BrokenGlass:你需要什么信息?

标签: c# linq


【解决方案1】:

试试

var Output = from s in ....
              select new MyModel() 
              {
                  TheCloseDate = s.TheCloseDate ?? null // Or whatever you want, like DateTime.Now
              }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-26
    • 1970-01-01
    • 2015-11-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多