mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-07-15 14:04:44 +08:00
Add SqlFunc.Exists
This commit is contained in:
parent
cd7dfd036d
commit
90367a461c
@ -572,6 +572,31 @@ namespace SqlSugar
|
||||
var parameter4 = model.Args[3];
|
||||
return $" STUFF ({parameter1.MemberName}, {parameter2.MemberName}, {parameter3.MemberName}, {parameter4.MemberName}) ";
|
||||
}
|
||||
public virtual string Exists(MethodCallExpressionModel model)
|
||||
{
|
||||
var parameter1 = model.Args[0];
|
||||
if (model.Args.Count > 1)
|
||||
{
|
||||
var parameter2 = model.Args[1];
|
||||
if (UtilMethods.IsParentheses(parameter1.MemberName))
|
||||
{
|
||||
parameter1.MemberName = $" {parameter1.MemberName.ObjToString().Trim().TrimEnd(')')} AND {parameter2.MemberName}) ";
|
||||
}
|
||||
else
|
||||
{
|
||||
parameter1.MemberName = $" {parameter1.MemberName} AND {parameter2.MemberName} ";
|
||||
}
|
||||
}
|
||||
if (UtilMethods.IsParentheses(parameter1.MemberName))
|
||||
{
|
||||
return $" Exists{parameter1.MemberName} ";
|
||||
}
|
||||
else
|
||||
{
|
||||
return $" Exists({parameter1.MemberName}) ";
|
||||
}
|
||||
}
|
||||
|
||||
public virtual string GetDateString(string dateValue, string format)
|
||||
{
|
||||
return null;
|
||||
|
@ -89,7 +89,7 @@ namespace SqlSugar
|
||||
string Stuff(MethodCallExpressionModel model);
|
||||
string RowNumber(MethodCallExpressionModel model);
|
||||
string RowCount(MethodCallExpressionModel model);
|
||||
|
||||
string Exists(MethodCallExpressionModel model);
|
||||
string GetDateString(string dateValue,string format);
|
||||
string GetForXmlPath();
|
||||
}
|
||||
|
@ -115,6 +115,23 @@ namespace SqlSugar
|
||||
{
|
||||
return thisValue.Equals(parameterValue);
|
||||
}
|
||||
|
||||
public static bool Exists(string subQueryableName_Or_OneToOnePropertyName)
|
||||
{
|
||||
throw new NotSupportedException("Can only be used in expressions");
|
||||
}
|
||||
public static bool Exists<valueType>(valueType subQueryableName_Or_OneToOnePropertyName) where valueType : struct
|
||||
{
|
||||
throw new NotSupportedException("Can only be used in expressions");
|
||||
}
|
||||
public static bool Exists(string subQueryableName_Or_OneToOnePropertyName, List<IConditionalModel> conditionalModels)
|
||||
{
|
||||
throw new NotSupportedException("Can only be used in expressions");
|
||||
}
|
||||
public static bool Exists<valueType>(valueType subQueryableName_Or_OneToOnePropertyName, List<IConditionalModel> conditionalModels) where valueType : struct
|
||||
{
|
||||
throw new NotSupportedException("Can only be used in expressions");
|
||||
}
|
||||
public static bool DateIsSame(DateTime date1, DateTime date2)
|
||||
{
|
||||
return date1.ToString("yyyy-MM-dd") == date2.ToString("yyyy-MM-dd");
|
||||
|
@ -1018,6 +1018,16 @@ namespace SqlSugar
|
||||
return this.Context.DbMehtods.RowNumber(model);
|
||||
case "RowCount":
|
||||
return this.Context.DbMehtods.RowCount(model);
|
||||
case "Exists":
|
||||
if (model.Args.Count > 1)
|
||||
{
|
||||
this.Context.Parameters.RemoveAll(it => model.Args[1].MemberName.ObjToString().Contains(it.ParameterName) );
|
||||
List<IConditionalModel> conditionalModels = (List<IConditionalModel>) model.Args[1].MemberValue;
|
||||
var sqlObj = this.Context.SugarContext.Context.Queryable<object>().SqlBuilder.ConditionalModelToSql(conditionalModels, 0);
|
||||
model.Args[1].MemberName = sqlObj.Key;
|
||||
this.Context.Parameters.AddRange(sqlObj.Value);
|
||||
}
|
||||
return this.Context.DbMehtods.Exists(model);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -16,6 +16,10 @@ namespace SqlSugar
|
||||
{
|
||||
public class UtilMethods
|
||||
{
|
||||
public static bool IsParentheses(object name)
|
||||
{
|
||||
return name.ObjToString().Trim().Last() == ')' && name.ObjToString().Trim().First() == '(';
|
||||
}
|
||||
|
||||
internal static bool IsDefaultValue(object value)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user