mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-07-15 23:13:42 +08:00
Add SqlFunc.GetSelfAndAutoFill
This commit is contained in:
parent
cf71763d53
commit
c74d460885
@ -15,4 +15,8 @@ namespace OrmTest.Models
|
|||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
public Student Student { get; set; }
|
public Student Student { get; set; }
|
||||||
}
|
}
|
||||||
|
public class ViewModelStudent3: Student
|
||||||
|
{
|
||||||
|
public string SchoolName { get; set; }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,6 +27,7 @@ namespace OrmTest.UnitTest
|
|||||||
single4();
|
single4();
|
||||||
single5();
|
single5();
|
||||||
Multiple();
|
Multiple();
|
||||||
|
Multiple2();
|
||||||
singleDynamic();
|
singleDynamic();
|
||||||
MultipleDynamic();
|
MultipleDynamic();
|
||||||
}
|
}
|
||||||
@ -51,8 +52,26 @@ namespace OrmTest.UnitTest
|
|||||||
},
|
},
|
||||||
"Select.Multiple Error");
|
"Select.Multiple Error");
|
||||||
}
|
}
|
||||||
|
private void Multiple2()
|
||||||
|
{
|
||||||
|
Expression<Func<Student, School, object>> exp = (it, school) => new ViewModelStudent3() { SchoolName=school.Name,Id=SqlFunc.GetSelfAndAutoFill(it.Id) };
|
||||||
|
ExpressionContext expContext = new ExpressionContext();
|
||||||
|
expContext.IsSingle = false;
|
||||||
|
expContext.Resolve(exp, ResolveExpressType.SelectMultiple);
|
||||||
|
var selectorValue = expContext.Result.GetString();
|
||||||
|
var pars = expContext.Parameters;
|
||||||
|
base.Check(
|
||||||
|
selectorValue,
|
||||||
|
pars,
|
||||||
|
@" [school].[Name] AS [SchoolName] ,it.*",
|
||||||
|
new List<SugarParameter>(){
|
||||||
|
|
||||||
|
},
|
||||||
|
"Select.Multiple Error");
|
||||||
|
}
|
||||||
|
|
||||||
private void MultipleDynamic()
|
|
||||||
|
private void MultipleDynamic()
|
||||||
{
|
{
|
||||||
Expression<Func<Student, School, object>> exp = (it, school) => new { Name = "a", Id = it.Id / 2, SchoolId = school.Id };
|
Expression<Func<Student, School, object>> exp = (it, school) => new { Name = "a", Id = it.Id / 2, SchoolId = school.Id };
|
||||||
ExpressionContext expContext = new ExpressionContext();
|
ExpressionContext expContext = new ExpressionContext();
|
||||||
|
@ -179,6 +179,7 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
public virtual string GetAsString(string asName, string fieldValue)
|
public virtual string GetAsString(string asName, string fieldValue)
|
||||||
{
|
{
|
||||||
|
if (fieldValue.Contains(".*")) return fieldValue;
|
||||||
return string.Format(" {0} {1} {2} ", GetTranslationColumnName(fieldValue), "AS", GetTranslationColumnName(asName));
|
return string.Format(" {0} {1} {2} ", GetTranslationColumnName(fieldValue), "AS", GetTranslationColumnName(asName));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -189,6 +190,7 @@ namespace SqlSugar
|
|||||||
|
|
||||||
public virtual string GetAsString(string asName, string fieldValue, string fieldShortName)
|
public virtual string GetAsString(string asName, string fieldValue, string fieldShortName)
|
||||||
{
|
{
|
||||||
|
if (fieldValue.Contains(".*")) return fieldValue;
|
||||||
return string.Format(" {0} {1} {2} ", GetTranslationColumnName(fieldShortName + "." + fieldValue), "AS", GetTranslationColumnName(asName));
|
return string.Format(" {0} {1} {2} ", GetTranslationColumnName(fieldShortName + "." + fieldValue), "AS", GetTranslationColumnName(asName));
|
||||||
}
|
}
|
||||||
public virtual void Clear()
|
public virtual void Clear()
|
||||||
|
@ -6,7 +6,7 @@ using System.Text;
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
namespace SqlSugar
|
namespace SqlSugar
|
||||||
{
|
{
|
||||||
public partial class DefaultDbMethod : IDbMethods
|
public partial class DefaultDbMethod : IDbMethods
|
||||||
{
|
{
|
||||||
public virtual string IIF(MethodCallExpressionModel model)
|
public virtual string IIF(MethodCallExpressionModel model)
|
||||||
{
|
{
|
||||||
@ -273,7 +273,14 @@ namespace SqlSugar
|
|||||||
|
|
||||||
public string GuidNew()
|
public string GuidNew()
|
||||||
{
|
{
|
||||||
return "'"+Guid.NewGuid()+"' ";
|
return "'" + Guid.NewGuid() + "' ";
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GetSelfAndAutoFill(string shortName, bool isSingle)
|
||||||
|
{
|
||||||
|
if (isSingle) return "*";
|
||||||
|
else
|
||||||
|
return string.Format("{0}.*", shortName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -47,7 +47,7 @@ namespace SqlSugar
|
|||||||
string AggregateMax(MethodCallExpressionModel model);
|
string AggregateMax(MethodCallExpressionModel model);
|
||||||
string AggregateCount(MethodCallExpressionModel model);
|
string AggregateCount(MethodCallExpressionModel model);
|
||||||
string MappingColumn(MethodCallExpressionModel model);
|
string MappingColumn(MethodCallExpressionModel model);
|
||||||
string GetSelfAndAutoFill(MethodCallExpressionModel model);
|
string GetSelfAndAutoFill(string shortName,bool isSingle);
|
||||||
string True();
|
string True();
|
||||||
string False();
|
string False();
|
||||||
string GuidNew();
|
string GuidNew();
|
||||||
|
@ -101,6 +101,6 @@ namespace SqlSugar
|
|||||||
/// <typeparam name="TResult"></typeparam>
|
/// <typeparam name="TResult"></typeparam>
|
||||||
/// <param name="value"></param>
|
/// <param name="value"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static TResult GetSelfAndAutoFill<TResult>(object value) { throw new NotSupportedException("This method is not supported by the current parameter"); }
|
public static TResult GetSelfAndAutoFill<TResult>(TResult value) { throw new NotSupportedException("This method is not supported by the current parameter"); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -67,6 +67,7 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
case ResolveExpressType.WhereSingle:
|
case ResolveExpressType.WhereSingle:
|
||||||
case ResolveExpressType.WhereMultiple:
|
case ResolveExpressType.WhereMultiple:
|
||||||
|
Check.Exception(name == "GetSelfAndAutoFill", "SqlFunc.GetSelfAndAutoFill can only be used in Select.");
|
||||||
Where(parameter, isLeft, name, args, model);
|
Where(parameter, isLeft, name, args, model);
|
||||||
break;
|
break;
|
||||||
case ResolveExpressType.SelectSingle:
|
case ResolveExpressType.SelectSingle:
|
||||||
@ -111,21 +112,29 @@ namespace SqlSugar
|
|||||||
|
|
||||||
private void Select(ExpressionParameter parameter, bool? isLeft, string name, IEnumerable<Expression> args, MethodCallExpressionModel model, List<MethodCallExpressionArgs> appendArgs = null)
|
private void Select(ExpressionParameter parameter, bool? isLeft, string name, IEnumerable<Expression> args, MethodCallExpressionModel model, List<MethodCallExpressionArgs> appendArgs = null)
|
||||||
{
|
{
|
||||||
foreach (var item in args)
|
if (name == "GetSelfAndAutoFill")
|
||||||
{
|
{
|
||||||
var isBinaryExpression = item is BinaryExpression || item is MethodCallExpression;
|
var memberValue = (args.First() as MemberExpression).Expression.ToString();
|
||||||
if (isBinaryExpression)
|
model.Args.Add(new MethodCallExpressionArgs() { MemberValue= memberValue, IsMember=true, MemberName= memberValue });
|
||||||
{
|
|
||||||
model.Args.Add(GetMethodCallArgs(parameter, item));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Default(parameter, model, item);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (appendArgs != null)
|
else
|
||||||
{
|
{
|
||||||
model.Args.AddRange(appendArgs);
|
foreach (var item in args)
|
||||||
|
{
|
||||||
|
var isBinaryExpression = item is BinaryExpression || item is MethodCallExpression;
|
||||||
|
if (isBinaryExpression)
|
||||||
|
{
|
||||||
|
model.Args.Add(GetMethodCallArgs(parameter, item));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Default(parameter, model, item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (appendArgs != null)
|
||||||
|
{
|
||||||
|
model.Args.AddRange(appendArgs);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
parameter.BaseParameter.CommonTempData = GetMdthodValue(name, model);
|
parameter.BaseParameter.CommonTempData = GetMdthodValue(name, model);
|
||||||
}
|
}
|
||||||
@ -269,6 +278,9 @@ namespace SqlSugar
|
|||||||
Check.Exception(!isValid, "SqlFunc.MappingColumn parameters error, The property name on the left, string value on the right");
|
Check.Exception(!isValid, "SqlFunc.MappingColumn parameters error, The property name on the left, string value on the right");
|
||||||
this.Context.Parameters.RemoveAll(it => it.ParameterName == model.Args[1].MemberName.ObjToString());
|
this.Context.Parameters.RemoveAll(it => it.ParameterName == model.Args[1].MemberName.ObjToString());
|
||||||
return mappingColumnResult;
|
return mappingColumnResult;
|
||||||
|
case "GetSelfAndAutoFill":
|
||||||
|
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);
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -31,5 +31,5 @@ using System.Runtime.InteropServices;
|
|||||||
// You can specify all the values or you can default the Build and Revision Numbers
|
// You can specify all the values or you can default the Build and Revision Numbers
|
||||||
// by using the '*' as shown below:
|
// by using the '*' as shown below:
|
||||||
// [assembly: AssemblyVersion("1.0.*")]
|
// [assembly: AssemblyVersion("1.0.*")]
|
||||||
[assembly: AssemblyVersion("4.2.0.9")]
|
[assembly: AssemblyVersion("4.2.1")]
|
||||||
[assembly: AssemblyFileVersion("4.2.0.9")]
|
[assembly: AssemblyFileVersion("4.2.1")]
|
||||||
|
Loading…
Reference in New Issue
Block a user