mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-04-24 18:04:52 +08:00
Subquery
This commit is contained in:
parent
80d0a8642d
commit
94eef1e3e9
@ -102,5 +102,11 @@ namespace SqlSugar
|
||||
/// <param name="value"></param>
|
||||
/// <returns></returns>
|
||||
public static TResult GetSelfAndAutoFill<TResult>(TResult value) { throw new NotSupportedException("Can only be used in expressions"); }
|
||||
/// <summary>
|
||||
/// Subquery
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <returns></returns>
|
||||
public static Subqueryable<T> Subqueryable<T>() where T:class,new(){ throw new NotSupportedException("Can only be used in expressions");}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Text;
|
||||
|
||||
namespace SqlSugar
|
||||
{
|
||||
public interface ISubOperation
|
||||
{
|
||||
string Name { get; }
|
||||
string GetValue(ExpressionContext context, Expression expression);
|
||||
int Sort { get; }
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Text;
|
||||
|
||||
namespace SqlSugar
|
||||
{
|
||||
public class SubAny : ISubOperation
|
||||
{
|
||||
public string Name
|
||||
{
|
||||
get
|
||||
{
|
||||
return "Any";
|
||||
}
|
||||
}
|
||||
|
||||
public int Sort
|
||||
{
|
||||
get
|
||||
{
|
||||
return 1000;
|
||||
}
|
||||
}
|
||||
|
||||
public string GetValue(ExpressionContext context, Expression expression)
|
||||
{
|
||||
return ">0";
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Text;
|
||||
|
||||
namespace SqlSugar
|
||||
{
|
||||
public class SubBegin : ISubOperation
|
||||
{
|
||||
public string Name
|
||||
{
|
||||
get
|
||||
{
|
||||
return "Begin";
|
||||
}
|
||||
}
|
||||
|
||||
public int Sort
|
||||
{
|
||||
get
|
||||
{
|
||||
return 100;
|
||||
}
|
||||
}
|
||||
|
||||
public string GetValue(ExpressionContext context, Expression expression)
|
||||
{
|
||||
return "SELECT";
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Text;
|
||||
|
||||
namespace SqlSugar
|
||||
{
|
||||
public class SubFromTable : ISubOperation
|
||||
{
|
||||
public string Name
|
||||
{
|
||||
get
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
public int Sort
|
||||
{
|
||||
get
|
||||
{
|
||||
return 300;
|
||||
}
|
||||
}
|
||||
public string GetValue(ExpressionContext context, Expression expression = null)
|
||||
{
|
||||
return context.GetTranslationTableName(expression.Type.Name, true);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Text;
|
||||
|
||||
namespace SqlSugar
|
||||
{
|
||||
public class SubSelect : ISubOperation
|
||||
{
|
||||
public string Name
|
||||
{
|
||||
get
|
||||
{
|
||||
return "Select";
|
||||
}
|
||||
}
|
||||
|
||||
public int Sort
|
||||
{
|
||||
get
|
||||
{
|
||||
return 200;
|
||||
}
|
||||
}
|
||||
|
||||
public string GetValue(ExpressionContext context, Expression expression = null)
|
||||
{
|
||||
var newContext=context.GetCopyContext();
|
||||
newContext.ParameterIndex = context.ParameterIndex;
|
||||
newContext.Resolve(expression, ResolveExpressType.SelectMultiple);
|
||||
context.Parameters.AddRange(newContext.Parameters);
|
||||
context.ParameterIndex = newContext.ParameterIndex;
|
||||
return newContext.Result.GetResultString();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Text;
|
||||
|
||||
namespace SqlSugar.ExpressionsToSql.Subquery
|
||||
{
|
||||
public class SubWhere : ISubOperation
|
||||
{
|
||||
public string Name
|
||||
{
|
||||
get { return "Where"; }
|
||||
}
|
||||
|
||||
public int Sort
|
||||
{
|
||||
get
|
||||
{
|
||||
return 400;
|
||||
}
|
||||
}
|
||||
|
||||
public string GetValue(ExpressionContext context, Expression expression = null)
|
||||
{
|
||||
var newContext = context.GetCopyContext();
|
||||
newContext.ParameterIndex = context.ParameterIndex;
|
||||
newContext.Resolve(expression, ResolveExpressType.WhereMultiple);
|
||||
context.Parameters.AddRange(newContext.Parameters);
|
||||
context.ParameterIndex = newContext.ParameterIndex;
|
||||
return newContext.Result.GetResultString();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Text;
|
||||
|
||||
namespace SqlSugar
|
||||
{
|
||||
/// <summary>
|
||||
/// 开发中....
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
public class Subqueryable<T> where T : class, new()
|
||||
{
|
||||
public Subqueryable<T> Where(Func<T, bool> expression)
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
public TResult Select<TResult>(Func<T, TResult> expression) where TResult :struct
|
||||
{
|
||||
return default(TResult);
|
||||
}
|
||||
public string Select(Func<T, string> expression)
|
||||
{
|
||||
return default(string);
|
||||
}
|
||||
|
||||
public bool Any()
|
||||
{
|
||||
return default(bool);
|
||||
}
|
||||
|
||||
public bool Count()
|
||||
{
|
||||
return default(bool);
|
||||
}
|
||||
}
|
||||
}
|
@ -72,6 +72,13 @@
|
||||
<Compile Include="Abstract\InsertableProvider\InsertableProvider.cs" />
|
||||
<Compile Include="Abstract\DeleteProvider\DeleteableProvider.cs" />
|
||||
<Compile Include="Enum\DbType.cs" />
|
||||
<Compile Include="ExpressionsToSql\Subquery\Items\ISubAction.cs" />
|
||||
<Compile Include="ExpressionsToSql\Subquery\Items\SubFromTable.cs" />
|
||||
<Compile Include="ExpressionsToSql\Subquery\Items\SubAny.cs" />
|
||||
<Compile Include="ExpressionsToSql\Subquery\Items\SubBegin%27.cs" />
|
||||
<Compile Include="ExpressionsToSql\Subquery\Items\SubSelect.cs" />
|
||||
<Compile Include="ExpressionsToSql\Subquery\Subquerable.cs" />
|
||||
<Compile Include="ExpressionsToSql\Subquery\Items\SubWhere.cs" />
|
||||
<Compile Include="Infrastructure\DependencyManagement.cs" />
|
||||
<Compile Include="Utilities\JsonHelper.cs" />
|
||||
<Compile Include="Utilities\ReflectionExtensions.cs" />
|
||||
|
Loading…
Reference in New Issue
Block a user