This commit is contained in:
sunkaixuan 2017-09-16 01:49:23 +08:00
parent 80d0a8642d
commit 94eef1e3e9
9 changed files with 233 additions and 0 deletions

View File

@ -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");}
}
}

View File

@ -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; }
}
}

View File

@ -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";
}
}
}

View File

@ -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";
}
}
}

View File

@ -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);
}
}
}

View File

@ -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();
}
}
}

View File

@ -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();
}
}
}

View File

@ -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);
}
}
}

View File

@ -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" />