如何在LINQ to SQL中结合日期和时间

时间:2018-06-07 06:39:09

标签: sql-server vb.net linq-to-sql

使用Linq to SQL,我想首先合并这两个字段:DateEnterDate?类型)和TimeEnterInteger?类型)。按降序模式对它们进行排序。将合并的DateEnterTimeEnter合并到select的一个字段中。

我一直不支持翻译sql的方法。

Dim query = From a In dataContext.Orders
            Join b In dataContext.OrderStatus On b.OrderName Equals a.Name
            Where b.Status = "Finished"
            Let UpdatedAt = b.DateEnter + TimeSpan.FromHours(b.TimeEnter)
            Order By UpdatedAt Descending
            Select New With {
                Key .LastUpdatedAt = UpdatedAt,
                Key .Name = a.Name,
                Key .Owner = a.OrderOwner}

1 个答案:

答案 0 :(得分:0)

Dim query = From a In dataContext.Orders
            Join b In dataContext.OrderStatus On b.OrderName Equals a.Name
            Where b.Status = "Finished"
            Order By b.DateEnter.Value.AddSeconds(b.TimeEnter) Descending
            Select New With {
                Key .LastUpdatedAt = b.DateEnter.Value.AddSeconds(b.TimeEnter)
                Key .Name = a.Name,
                Key .Owner = a.OrderOwner}

能够得到它。