Browse Source

Add SqlFunc.GetDate()

pull/12/MERGE
sunkaixuan 7 years ago
parent
commit
b167666870
  1. 2
      Src/Asp.Net/SqlServerTest/Demos/1_Query.cs
  2. 7
      Src/Asp.Net/SqlSugar/ExpressionsToSql/DbMethods/DefaultDbMethod.cs
  3. 1
      Src/Asp.Net/SqlSugar/ExpressionsToSql/DbMethods/IDbMethods.cs
  4. 1
      Src/Asp.Net/SqlSugar/ExpressionsToSql/DbMethods/SqlFunc.cs
  5. 2
      Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve.cs

2
Src/Asp.Net/SqlServerTest/Demos/1_Query.cs

@ -283,7 +283,7 @@ namespace OrmTest.Demo
var getUnionAllList2 = db.UnionAll(db.Queryable<Student>(), db.Queryable<Student>()).ToList(); var getUnionAllList2 = db.UnionAll(db.Queryable<Student>(), db.Queryable<Student>()).ToList();
var test1 = db.Queryable<Student, School>((st, sc) => st.SchoolId == sc.Id).Select((st, sc) => SqlFunc.ToInt64(sc.Id)).ToList(); var test1 = db.Queryable<Student, School>((st, sc) => st.SchoolId == sc.Id).Where(st=>st.CreateTime>SqlFunc.GetDate()).Select((st, sc) => SqlFunc.ToInt64(sc.Id)).ToList();
} }
public static void Page() public static void Page()
{ {

7
Src/Asp.Net/SqlSugar/ExpressionsToSql/DbMethods/DefaultDbMethod.cs

@ -275,7 +275,7 @@ namespace SqlSugar
{ {
var parameter = model.Args[0]; var parameter = model.Args[0];
var parameter1 = model.Args[1]; var parameter1 = model.Args[1];
return string.Format("ISNULL({0},{1})",parameter.MemberName,parameter1.MemberName); return string.Format("ISNULL({0},{1})", parameter.MemberName, parameter1.MemberName);
} }
public virtual string True() public virtual string True()
@ -319,5 +319,10 @@ namespace SqlSugar
{ {
return "NULL"; return "NULL";
} }
public virtual string GetDate()
{
return "GETDATE()";
}
} }
} }

1
Src/Asp.Net/SqlSugar/ExpressionsToSql/DbMethods/IDbMethods.cs

@ -57,5 +57,6 @@ namespace SqlSugar
string EqualTrue(string value); string EqualTrue(string value);
string Pack(string sql); string Pack(string sql);
string Null(); string Null();
string GetDate();
} }
} }

1
Src/Asp.Net/SqlSugar/ExpressionsToSql/DbMethods/SqlFunc.cs

@ -109,6 +109,7 @@ namespace SqlSugar
/// <param name="value"></param> /// <param name="value"></param>
/// <returns></returns> /// <returns></returns>
public static TResult GetSelfAndAutoFill<TResult>(TResult value) { throw new NotSupportedException("Can only be used in expressions"); } public static TResult GetSelfAndAutoFill<TResult>(TResult value) { throw new NotSupportedException("Can only be used in expressions"); }
public static DateTime GetDate() { throw new NotSupportedException("Can only be used in expressions"); }
/// <summary> /// <summary>
/// Subquery /// Subquery
/// </summary> /// </summary>

2
Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve.cs

@ -414,6 +414,8 @@ namespace SqlSugar
case "GetSelfAndAutoFill": case "GetSelfAndAutoFill":
this.Context.Parameters.RemoveAll(it => it.ParameterName == model.Args[0].MemberName.ObjToString()); this.Context.Parameters.RemoveAll(it => it.ParameterName == model.Args[0].MemberName.ObjToString());
return this.Context.DbMehtods.GetSelfAndAutoFill(model.Args[0].MemberValue.ObjToString(), this.Context.IsSingle); return this.Context.DbMehtods.GetSelfAndAutoFill(model.Args[0].MemberValue.ObjToString(), this.Context.IsSingle);
case "GetDate":
return this.Context.DbMehtods.GetDate();
default: default:
break; break;
} }

Loading…
Cancel
Save