mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-08-24 07:22:57 +08:00
Add SqlFunc.GetRandom
This commit is contained in:
parent
46a9cbe82a
commit
89c0e03975
@ -8,8 +8,8 @@ namespace OrmTest
|
|||||||
{
|
{
|
||||||
public class Config
|
public class Config
|
||||||
{
|
{
|
||||||
public static string ConnectionString = "server=.;uid=sa;pwd=sasa;database=SqlSugar4XTest";
|
public static string ConnectionString = "server=.;uid=sa;pwd=@jhl85661501;database=SqlSugar4XTest";
|
||||||
public static string ConnectionString2 = "server=.;uid=sa;pwd=sasa;database=SQLSUGAR4XTEST";
|
public static string ConnectionString2 = "server=.;uid=sa;pwd=@jhl85661501;database=SQLSUGAR4XTEST";
|
||||||
public static string ConnectionString3 = "server=.;uid=sa;pwd=sasa;database=sqlsugar4xtest";
|
public static string ConnectionString3 = "server=.;uid=sa;pwd=@jhl85661501;database=sqlsugar4xtest";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -244,6 +244,8 @@ namespace OrmTest.Demo
|
|||||||
var db = GetInstance();
|
var db = GetInstance();
|
||||||
var dbTime = db.GetDate();
|
var dbTime = db.GetDate();
|
||||||
var getAll = db.Queryable<Student>().Select<object>("*").ToList();
|
var getAll = db.Queryable<Student>().Select<object>("*").ToList();
|
||||||
|
var getAll2 = db.Queryable<Student>().ToList();
|
||||||
|
var getRandomList = db.Queryable<Student>().OrderBy(it => SqlFunc.GetRandom()).ToList();
|
||||||
var getAllOrder = db.Queryable<Student>().OrderBy(it => it.Id).OrderBy(it => it.Name, OrderByType.Desc).ToList();
|
var getAllOrder = db.Queryable<Student>().OrderBy(it => it.Id).OrderBy(it => it.Name, OrderByType.Desc).ToList();
|
||||||
var getId = db.Queryable<Student>().Select(it => it.Id).ToList();
|
var getId = db.Queryable<Student>().Select(it => it.Id).ToList();
|
||||||
var getNew = db.Queryable<Student>().Where(it => it.Id == 1).Select(it => new { id = SqlFunc.IIF(it.Id == 0, 1, it.Id), it.Name, it.SchoolId }).ToList();
|
var getNew = db.Queryable<Student>().Where(it => it.Id == 1).Select(it => new { id = SqlFunc.IIF(it.Id == 0, 1, it.Id), it.Name, it.SchoolId }).ToList();
|
||||||
|
@ -325,6 +325,11 @@ namespace SqlSugar
|
|||||||
return "GETDATE()";
|
return "GETDATE()";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public virtual string GetRandom()
|
||||||
|
{
|
||||||
|
return "NEWID()";
|
||||||
|
}
|
||||||
|
|
||||||
public virtual string CaseWhen(List<KeyValuePair<string, string>> sqls)
|
public virtual string CaseWhen(List<KeyValuePair<string, string>> sqls)
|
||||||
{
|
{
|
||||||
StringBuilder reslut = new StringBuilder();
|
StringBuilder reslut = new StringBuilder();
|
||||||
|
@ -59,5 +59,6 @@ namespace SqlSugar
|
|||||||
string Pack(string sql);
|
string Pack(string sql);
|
||||||
string Null();
|
string Null();
|
||||||
string GetDate();
|
string GetDate();
|
||||||
|
string GetRandom();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -110,6 +110,7 @@ namespace SqlSugar
|
|||||||
/// <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"); }
|
public static DateTime GetDate() { throw new NotSupportedException("Can only be used in expressions"); }
|
||||||
|
public static string GetRandom() { throw new NotSupportedException("Can only be used in expressions"); }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Subquery
|
/// Subquery
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -504,6 +504,8 @@ namespace SqlSugar
|
|||||||
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":
|
case "GetDate":
|
||||||
return this.Context.DbMehtods.GetDate();
|
return this.Context.DbMehtods.GetDate();
|
||||||
|
case "GetRandom":
|
||||||
|
return this.Context.DbMehtods.GetRandom();
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user