zoukankan      html  css  js  c++  java
  • entity framework 时间操作

    //新方法 entity framework 时间操作 
    query.Where(c => System.Data.Entity.DbFunctions.DiffDays(DateTime.Now, c.AddTime) == 0).Count();

    //比较天数

    //当天用户
    //方法已经过时
    var useractiveentity = db.UserActive.Where(u => u.UserInfoID == uid && System.Data.Objects.EntityFunctions.DiffDays(DateTime.Now, u.Createtime) == 0).FirstOrDefault(); if (useractiveentity == null) { UserActive userActive = new UserActive(); userActive.Createtime = DateTime.Now; userActive.UserInfoID = uid; db.UserActive.Add(userActive); db.SaveChanges(); }
    //比较小时

    //当前小时

    var useractiveentity = db.UserActive.Where(u => u.UserInfoID == uid && System.Data.Objects.EntityFunctions.DiffHours(DateTime.Now, u.Createtime) == 0).FirstOrDefault();

    //比较分钟
    //当前分钟
    var useractiveentity = db.UserActive.Where(u => u.UserInfoID == uid && System.Data.Objects.EntityFunctions.DiffMinutes(DateTime.Now, u.Createtime) == 0).FirstOrDefault();
     

    //System.Data.Objects.EntityFunctions 类中 // 摘要: // 调用 DiffDays 规范函数。 有关 DiffDays 规范函数的信息,请参见日期和时间规范函数。 // // 参数: // dateValue1: // 有效日期。 // // dateValue2: // 有效日期。 // // 返回结果: // dateValue1 和 dateValue2 之间的天数。 [EdmFunction("Edm", "DiffDays")] public static int? DiffDays(DateTime? dateValue1, DateTime? dateValue2); // // 摘要: // 调用 DiffDays 规范函数。 有关 DiffDays 规范函数的信息,请参见日期和时间规范函数。 // // 参数: // dateValue1: // 一个有效的日期时间偏移。 // // dateValue2: // 一个有效的日期时间偏移。 // // 返回结果: // dateValue1 和 dateValue2 之间的天数。 [EdmFunction("Edm", "DiffDays")] public static int? DiffDays(DateTimeOffset? dateValue1, DateTimeOffset? dateValue2); // // 摘要: // 调用 DiffHours 规范函数。 有关 DiffHours 规范函数的信息,请参见日期和时间规范函数。 // // 参数: // timeValue1: // 有效日期。 // // timeValue2: // 有效日期。 // // 返回结果: // timeValue1 和 timeValue2 之间的小时数。 [EdmFunction("Edm", "DiffHours")] public static int? DiffHours(DateTime? timeValue1, DateTime? timeValue2); // // 摘要: // 调用 DiffHours 规范函数。 有关 DiffHours 规范函数的信息,请参见日期和时间规范函数。 // // 参数: // timeValue1: // 一个有效的日期时间偏移。 // // timeValue2: // 一个有效的日期时间偏移。 // // 返回结果: // timeValue1 和 timeValue2 之间的小时数。 [EdmFunction("Edm", "DiffHours")] public static int? DiffHours(DateTimeOffset? timeValue1, DateTimeOffset? timeValue2); // // 摘要: // 调用 DiffHours 规范函数。 有关 DiffHours 规范函数的信息,请参见日期和时间规范函数。 // // 参数: // timeValue1: // 一个有效的时间跨度。 // // timeValue2: // 一个有效的时间跨度。 // // 返回结果: // timeValue1 和 timeValue2 之间的小时数。 [EdmFunction("Edm", "DiffHours")] public static int? DiffHours(TimeSpan? timeValue1, TimeSpan? timeValue2); // // 摘要: // 调用 DiffMicroseconds 规范函数。 有关 DiffMicroseconds 规范函数的信息,请参见日期和时间规范函数。 // // 参数: // timeValue1: // 有效日期。 // // timeValue2: // 有效日期。 // // 返回结果: // timeValue1 和 timeValue2 之间的微秒数。 [EdmFunction("Edm", "DiffMicroseconds")] public static int? DiffMicroseconds(DateTime? timeValue1, DateTime? timeValue2); // // 摘要: // 调用 DiffMicroseconds 规范函数。 有关 DiffMicroseconds 规范函数的信息,请参见日期和时间规范函数。 // // 参数: // timeValue1: // 一个有效的日期时间偏移。 // // timeValue2: // 一个有效的日期时间偏移。 // // 返回结果: // timeValue1 和 timeValue2 之间的微秒数。 [EdmFunction("Edm", "DiffMicroseconds")] public static int? DiffMicroseconds(DateTimeOffset? timeValue1, DateTimeOffset? timeValue2); // // 摘要: // 调用 DiffMicroseconds 规范函数。 有关 DiffMicroseconds 规范函数的信息,请参见日期和时间规范函数。 // // 参数: // timeValue1: // 一个有效的时间跨度。 // // timeValue2: // 一个有效的时间跨度。 // // 返回结果: // timeValue1 和 timeValue2 之间的微秒数。 [EdmFunction("Edm", "DiffMicroseconds")] public static int? DiffMicroseconds(TimeSpan? timeValue1, TimeSpan? timeValue2); // // 摘要: // 调用 DiffMilliseconds 规范函数。 有关 DiffMilliseconds 规范函数的信息,请参见日期和时间规范函数。 // // 参数: // timeValue1: // 有效日期。 // // timeValue2: // 有效日期。 // // 返回结果: // timeValue1 和 timeValue2 之间的毫秒数。 [EdmFunction("Edm", "DiffMilliseconds")] public static int? DiffMilliseconds(DateTime? timeValue1, DateTime? timeValue2); // // 摘要: // 调用 DiffMilliseconds 规范函数。 有关 DiffMilliseconds 规范函数的信息,请参见日期和时间规范函数。 // // 参数: // timeValue1: // 一个有效的日期时间偏移。 // // timeValue2: // 一个有效的日期时间偏移。 // // 返回结果: // timeValue1 和 timeValue2 之间的毫秒数。 [EdmFunction("Edm", "DiffMilliseconds")] public static int? DiffMilliseconds(DateTimeOffset? timeValue1, DateTimeOffset? timeValue2); // // 摘要: // 调用 DiffMilliseconds 规范函数。 有关 DiffMilliseconds 规范函数的信息,请参见日期和时间规范函数。 // // 参数: // timeValue1: // 一个有效的时间跨度。 // // timeValue2: // 一个有效的时间跨度。 // // 返回结果: // timeValue1 和 timeValue2 之间的毫秒数。 [EdmFunction("Edm", "DiffMilliseconds")] public static int? DiffMilliseconds(TimeSpan? timeValue1, TimeSpan? timeValue2); // // 摘要: // 调用 DiffMinutes 规范函数。 有关 DiffMinutes 规范函数的信息,请参见日期和时间规范函数。 // // 参数: // timeValue1: // 有效日期。 // // timeValue2: // 有效日期。 // // 返回结果: // timeValue1 和 timeValue2 之间的分钟数。 [EdmFunction("Edm", "DiffMinutes")] public static int? DiffMinutes(DateTime? timeValue1, DateTime? timeValue2); // // 摘要: // 调用 DiffMinutes 规范函数。 有关 DiffMinutes 规范函数的信息,请参见日期和时间规范函数。 // // 参数: // timeValue1: // 一个有效的日期时间偏移。 // // timeValue2: // 一个有效的日期时间偏移。 // // 返回结果: // timeValue1 和 timeValue2 之间的分钟数。 [EdmFunction("Edm", "DiffMinutes")] public static int? DiffMinutes(DateTimeOffset? timeValue1, DateTimeOffset? timeValue2); // // 摘要: // 调用 DiffMinutes 规范函数。 有关 DiffMinutes 规范函数的信息,请参见日期和时间规范函数。 // // 参数: // timeValue1: // 一个有效的时间跨度。 // // timeValue2: // 一个有效的时间跨度。 // // 返回结果: // timeValue1 和 timeValue2 之间的分钟数。 [EdmFunction("Edm", "DiffMinutes")] public static int? DiffMinutes(TimeSpan? timeValue1, TimeSpan? timeValue2); // // 摘要: // 调用 DiffMonths 规范函数。 有关 DiffMonths 规范函数的信息,请参见日期和时间规范函数。 // // 参数: // dateValue1: // 有效日期。 // // dateValue2: // 有效日期。 // // 返回结果: // dateValue1 和 dateValue2 之间的月数。 [EdmFunction("Edm", "DiffMonths")] public static int? DiffMonths(DateTime? dateValue1, DateTime? dateValue2); // // 摘要: // 调用 DiffMonths 规范函数。 有关 DiffMonths 规范函数的信息,请参见日期和时间规范函数。 // // 参数: // dateValue1: // 一个有效的日期时间偏移。 // // dateValue2: // 一个有效的日期时间偏移。 // // 返回结果: // dateValue1 和 dateValue2 之间的月数。 [EdmFunction("Edm", "DiffMonths")] public static int? DiffMonths(DateTimeOffset? dateValue1, DateTimeOffset? dateValue2); // // 摘要: // 调用 DiffNanoseconds 规范函数。 有关 DiffNanoseconds 规范函数的信息,请参见日期和时间规范函数。 // // 参数: // timeValue1: // 有效日期。 // // timeValue2: // 有效日期。 // // 返回结果: // timeValue1 和 timeValue2 之间的毫微秒数。 [EdmFunction("Edm", "DiffNanoseconds")] public static int? DiffNanoseconds(DateTime? timeValue1, DateTime? timeValue2); // // 摘要: // 调用 DiffNanoseconds 规范函数。 有关 DiffNanoseconds 规范函数的信息,请参见日期和时间规范函数。 // // 参数: // timeValue1: // 一个有效的日期时间偏移。 // // timeValue2: // 一个有效的日期时间偏移。 // // 返回结果: // timeValue1 和 timeValue2 之间的毫微秒数。 [EdmFunction("Edm", "DiffNanoseconds")] public static int? DiffNanoseconds(DateTimeOffset? timeValue1, DateTimeOffset? timeValue2); // // 摘要: // 调用 DiffNanoseconds 规范函数。 有关 DiffNanoseconds 规范函数的信息,请参见日期和时间规范函数。 // // 参数: // timeValue1: // 有效日期。 // // timeValue2: // 有效日期。 // // 返回结果: // timeValue1 和 timeValue2 之间的毫微秒数。 [EdmFunction("Edm", "DiffNanoseconds")] public static int? DiffNanoseconds(TimeSpan? timeValue1, TimeSpan? timeValue2); // // 摘要: // 调用 DiffSeconds 规范函数。 有关 DiffSeconds 规范函数的信息,请参见日期和时间规范函数。 // // 参数: // timeValue1: // 有效日期。 // // timeValue2: // 有效日期。 // // 返回结果: // timeValue1 和 timeValue2 之间的秒数。 [EdmFunction("Edm", "DiffSeconds")] public static int? DiffSeconds(DateTime? timeValue1, DateTime? timeValue2); // // 摘要: // 调用 DiffSeconds 规范函数。 有关 DiffSeconds 规范函数的信息,请参见日期和时间规范函数。 // // 参数: // timeValue1: // 一个有效的日期时间偏移。 // // timeValue2: // 一个有效的日期时间偏移。 // // 返回结果: // timeValue1 和 timeValue2 之间的秒数。 [EdmFunction("Edm", "DiffSeconds")] public static int? DiffSeconds(DateTimeOffset? timeValue1, DateTimeOffset? timeValue2); // // 摘要: // 调用 DiffSeconds 规范函数。 有关 DiffSeconds 规范函数的信息,请参见日期和时间规范函数。 // // 参数: // timeValue1: // 一个有效的时间跨度。 // // timeValue2: // 一个有效的时间跨度。 // // 返回结果: // timeValue1 和 timeValue2 之间的秒数。 [EdmFunction("Edm", "DiffSeconds")] public static int? DiffSeconds(TimeSpan? timeValue1, TimeSpan? timeValue2); // // 摘要: // 调用 DiffYears 规范函数。 有关 DiffYears 规范函数的信息,请参见日期和时间规范函数。 // // 参数: // dateValue1: // 有效日期。 // // dateValue2: // 有效日期。 // // 返回结果: // dateValue1 和 dateValue2 之间的年数。 [EdmFunction("Edm", "DiffYears")] public static int? DiffYears(DateTime? dateValue1, DateTime? dateValue2); // // 摘要: // 调用 DiffYears 规范函数。 有关 DiffYears 规范函数的信息,请参见日期和时间规范函数。 // // 参数: // dateValue1: // 一个有效的日期时间偏移。 // // dateValue2: // 一个有效的日期时间偏移。 // // 返回结果: // dateValue1 和 dateValue2 之间的年数。 [EdmFunction("Edm", "DiffYears")] public static int? DiffYears(DateTimeOffset? dateValue1, DateTimeOffset? dateValue2);
  • 相关阅读:
    UVA 679 Dropping Balls 由小见大,分析思考 二叉树放小球,开关翻转,小球最终落下叶子编号。
    2017-5-14 湘潭市赛 Similar Subsequence 分析+四维dp+一些简单优化
    Problem #3263 丽娃河的狼人传说 区间满足灯数,r排序后贪心。
    2017-5-14 湘潭市赛 Longest Common Subsequence 想法题
    2017-5-14 湘潭市赛 Parentheses 转化思想+贪心 使括号序列合法的最小花费。满足前面左括号的数量>=有括号的数量。
    deque双端队列用法
    Shell字符串截取
    keepAlived发生故障切换VIP—邮件通知方案2
    KeepAlived发生故障切换VIP—邮件通知方案1
    缺少依赖 libmysqlclient.so.18(64bit)的解决办法
  • 原文地址:https://www.cnblogs.com/zoro-zero/p/4565102.html
Copyright © 2011-2022 走看看