Browse Source

-

pull/12/MERGE
sunkaixuan 8 years ago
parent
commit
932d3d51a4
  1. 69
      SqlSugar/ExpressionsToSql/Method/DefaultDbMethod.cs
  2. 11
      SqlSugar/ExpressionsToSql/Method/IDbMethods.cs
  3. 15
      SqlSugar/ExpressionsToSql/Method/NBORM.cs
  4. 22
      SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve.cs

69
SqlSugar/ExpressionsToSql/Method/DefaultDbMethod.cs

@ -103,5 +103,74 @@ namespace SqlSugar
var parameter2 = model.Args[1];
return string.Format(" ({0}({1})) ", parameter2.Value, parameter.Value);
}
public string ToInt32(MethodCallExpressionModel model)
{
var parameter = model.Args[0];
return string.Format(" CAST({0} AS INT)", parameter.Value);
}
public string ToInt64(MethodCallExpressionModel model)
{
var parameter = model.Args[0];
return string.Format(" CAST({0} AS BIGINT)", parameter.Value);
}
public string ToString(MethodCallExpressionModel model)
{
var parameter = model.Args[0];
return string.Format(" CAST({0} AS NVARCHAR(MAX))", parameter.Value);
}
public string ToGuid(MethodCallExpressionModel model)
{
var parameter = model.Args[0];
return string.Format(" CAST({0} AS UNIQUEIDENTIFIER", parameter.Value);
}
public string ToDouble(MethodCallExpressionModel model)
{
var parameter = model.Args[0];
return string.Format(" CAST({0} AS FLOAT", parameter.Value);
}
public string ToBool(MethodCallExpressionModel model)
{
var parameter = model.Args[0];
return string.Format(" CAST({0} AS BIT", parameter.Value);
}
public string ToDate(MethodCallExpressionModel model)
{
var parameter = model.Args[0];
return string.Format(" CAST({0} AS DATETIME", parameter.Value);
}
public string ToDecimal(MethodCallExpressionModel model)
{
var parameter = model.Args[0];
return string.Format(" CAST({0} AS MONEY", parameter.Value);
}
public string Substring(MethodCallExpressionModel model)
{
var parameter = model.Args[0];
var parameter2 = model.Args[1];
var parameter3 = model.Args[2];
return string.Format("SUBSTRING({0},1 + {1},{2})", parameter.Value,parameter2.Value, parameter3.Value);
}
public string Length(MethodCallExpressionModel model)
{
var parameter = model.Args[0];
return string.Format("LEN({0})", parameter.Value);
}
public string Replace(MethodCallExpressionModel model)
{
var parameter = model.Args[0];
var parameter2 = model.Args[1];
var parameter3 = model.Args[2];
return string.Format("REPLACE({0},{1},{2})", parameter.Value, parameter2.Value, parameter3.Value);
}
}
}

11
SqlSugar/ExpressionsToSql/Method/IDbMethods.cs

@ -25,5 +25,16 @@ namespace SqlSugar
string Between(MethodCallExpressionModel model);
string StartsWith(MethodCallExpressionModel model);
string EndsWith(MethodCallExpressionModel model);
string ToInt32(MethodCallExpressionModel model);
string ToInt64(MethodCallExpressionModel model);
string ToString(MethodCallExpressionModel model);
string ToGuid(MethodCallExpressionModel model);
string ToDouble(MethodCallExpressionModel model);
string ToBool(MethodCallExpressionModel model);
string Substring(MethodCallExpressionModel model);
string ToDate(MethodCallExpressionModel model);
string ToDecimal(MethodCallExpressionModel model);
string Length(MethodCallExpressionModel model);
string Replace(MethodCallExpressionModel model);
}
}

15
SqlSugar/ExpressionsToSql/Method/NBORM.cs

@ -13,8 +13,8 @@ namespace SqlSugar
public static string ToUpper(object thisValue) { throw new NotImplementedException(); }
public static string Trim(object thisValue) { throw new NotImplementedException(); }
public static bool Contains(string thisValue, string parameterValue) { throw new NotImplementedException();}
public static bool StartsWith(string thisValue, string parameterValue) { throw new NotImplementedException(); }
public static bool EndsWith(string thisValue, string parameterValue) { throw new NotImplementedException(); }
public static bool StartsWith(object thisValue, string parameterValue) { throw new NotImplementedException(); }
public static bool EndsWith(object thisValue, string parameterValue) { throw new NotImplementedException(); }
public new static bool Equals(object thisValue, object parameterValue) { throw new NotImplementedException(); }
public static bool DateIsSame(DateTime date1, DateTime date2) { throw new NotImplementedException();}
public static bool DateIsSame(DateTime date1, DateTime date2, DateType dataType) { throw new NotImplementedException(); }
@ -22,5 +22,16 @@ namespace SqlSugar
public static DateTime DateAdd(DateTime date, int addValue) { throw new NotImplementedException(); }
public static int DateValue(DateTime date, DateType dataType) { throw new NotImplementedException(); }
public static bool Between(object value, object start, object end){ throw new NotImplementedException();}
public static int ToInt32(object value) { throw new NotImplementedException(); }
public static long ToInt64(object value) { throw new NotImplementedException(); }
public static DateTime ToDate(object value) { throw new NotImplementedException(); }
public static string ToString(object value) { throw new NotImplementedException(); }
public static decimal ToDecimal(object value) { throw new NotImplementedException(); }
public static Guid ToGuid(object value) { throw new NotImplementedException(); }
public static double ToDouble(object value) { throw new NotImplementedException(); }
public static bool ToBool(object value) { throw new NotImplementedException(); }
public static string Substring(object value, int index, int length) { throw new NotImplementedException(); }
public static string Replace(object value,string oldChar, string newChar) { throw new NotImplementedException(); }
public static int Length(object value) { throw new NotImplementedException(); }
}
}

22
SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve.cs

@ -98,6 +98,28 @@ namespace SqlSugar
return this.Context.DbMehtods.StartsWith(model);
case "EndsWith":
return this.Context.DbMehtods.EndsWith(model);
case "ToInt32":
return this.Context.DbMehtods.ToInt32(model);
case "ToInt64":
return this.Context.DbMehtods.ToInt64(model);
case "ToDate":
return this.Context.DbMehtods.ToDate(model);
case "ToString":
return this.Context.DbMehtods.ToString(model);
case "ToDecimal":
return this.Context.DbMehtods.ToDecimal(model);
case "ToGuid":
return this.Context.DbMehtods.ToGuid(model);
case "ToDouble":
return this.Context.DbMehtods.ToDouble(model);
case "ToBool":
return this.Context.DbMehtods.ToBool(model);
case "Substring":
return this.Context.DbMehtods.Substring(model);
case "Replace":
return this.Context.DbMehtods.Replace(model);
case "Length":
return this.Context.DbMehtods.Length(model);
default:
break;
}

Loading…
Cancel
Save