How to add day to date in Linq to SQL

前端 未结 10 1134
栀梦
栀梦 2020-12-16 13:53

I am writing this code. Here dt is input into the function, as well as someint. The column Exp is a T-SQL date column, which comes as a DateTime through Linq.



        
10条回答
  •  一向
    一向 (楼主)
    2020-12-16 14:37

    I solve my problem with that query.

    return (from a in dataContext.TableOfA
           where a.name == "Test" &&
           DbFunctions.AddHours(DbFunctions.CreateDateTime(
     a.Exp.Value.Year,a.Exp.Value.Month,a.Exp.Value.Day,a.Exp.Value.Hour,a.Exp.Value.Minute,
    a.Exp.Value.Millisecond),Someint) >=     
    DbFunctions.CreateDateTimeOffset(dt.Year,dt.Month,dt.Day,dt.Hour,dt.Minute,dt.Millisecond,0)
           select a).First();
    

提交回复
热议问题