Add Sqlfunc.CharIndex

This commit is contained in:
sunkaixuan 2019-05-14 13:11:07 +08:00
parent 91213483aa
commit 3d88df0e3d
8 changed files with 34 additions and 0 deletions

View File

@ -16,6 +16,17 @@ namespace OrmTest
Async(); Async();
NoEntity(); NoEntity();
Mapper(); Mapper();
SqlFuncTest();
}
private static void SqlFuncTest()
{
Console.WriteLine("");
Console.WriteLine("#### SqlFunc Start ####");
var db = GetInstance();
var index= db.Queryable<Order>().Select(it => SqlFunc.CharIndex("a", "cccacc")).First();
Console.WriteLine("#### End Start ####");
} }
private static void Mapper() private static void Mapper()

View File

@ -353,5 +353,9 @@ namespace SqlSugar
} }
return reslut.ToString(); return reslut.ToString();
} }
public virtual string CharIndex(MethodCallExpressionModel model)
{
return string.Format("CHARINDEX ({0},{1})", model.Args[0].MemberName, model.Args[1].MemberName);
}
} }
} }

View File

@ -60,5 +60,6 @@ namespace SqlSugar
string Null(); string Null();
string GetDate(); string GetDate();
string GetRandom(); string GetRandom();
string CharIndex(MethodCallExpressionModel model);
} }
} }

View File

@ -118,5 +118,6 @@ namespace SqlSugar
/// <returns></returns> /// <returns></returns>
public static Subqueryable<T> Subqueryable<T>() where T:class,new(){ throw new NotSupportedException("Can only be used in expressions");} public static Subqueryable<T> Subqueryable<T>() where T:class,new(){ throw new NotSupportedException("Can only be used in expressions");}
public static CaseThen IF(bool condition) { throw new NotSupportedException("Can only be used in expressions"); } public static CaseThen IF(bool condition) { throw new NotSupportedException("Can only be used in expressions"); }
public static int CharIndex(string findChar,string searchValue) { throw new NotSupportedException("Can only be used in expressions"); }
} }
} }

View File

@ -585,6 +585,8 @@ namespace SqlSugar
return this.Context.DbMehtods.GetDate(); return this.Context.DbMehtods.GetDate();
case "GetRandom": case "GetRandom":
return this.Context.DbMehtods.GetRandom(); return this.Context.DbMehtods.GetRandom();
case "CharIndex":
return this.Context.DbMehtods.CharIndex(model);
default: default:
break; break;
} }

View File

@ -138,5 +138,10 @@ namespace SqlSugar
{ {
return "rand()"; return "rand()";
} }
public override string CharIndex(MethodCallExpressionModel model)
{
return string.Format("instr ({0},{1})", model.Args[0].MemberName, model.Args[1].MemberName);
}
} }
} }

View File

@ -185,5 +185,10 @@ namespace SqlSugar
{ {
return "dbms_random.value"; return "dbms_random.value";
} }
public override string CharIndex(MethodCallExpressionModel model)
{
return string.Format("instr ({0},{1},1,1) ", model.Args[0].MemberName, model.Args[1].MemberName);
}
} }
} }

View File

@ -221,5 +221,10 @@ namespace SqlSugar
{ {
return "RANDOM()"; return "RANDOM()";
} }
public override string CharIndex(MethodCallExpressionModel model)
{
throw new NotSupportedException("Slqite Not Supported CharIndex");
}
} }
} }