From 94eef1e3e975bf5d67cbec452437311471d17538 Mon Sep 17 00:00:00 2001
From: sunkaixuan <610262374@qq.com>
Date: Sat, 16 Sep 2017 01:49:23 +0800
Subject: [PATCH] Subquery
---
.../ExpressionsToSql/DbMethods/SqlFunc.cs | 6 +++
.../Subquery/Items/ISubAction.cs | 15 +++++++
.../ExpressionsToSql/Subquery/Items/SubAny.cs | 32 +++++++++++++++
.../Subquery/Items/SubBegin'.cs | 32 +++++++++++++++
.../Subquery/Items/SubFromTable.cs | 31 +++++++++++++++
.../Subquery/Items/SubSelect.cs | 37 ++++++++++++++++++
.../Subquery/Items/SubWhere.cs | 34 ++++++++++++++++
.../ExpressionsToSql/Subquery/Subquerable.cs | 39 +++++++++++++++++++
Src/Asp.Net/SqlSugar/SqlSugar.csproj | 7 ++++
9 files changed, 233 insertions(+)
create mode 100644 Src/Asp.Net/SqlSugar/ExpressionsToSql/Subquery/Items/ISubAction.cs
create mode 100644 Src/Asp.Net/SqlSugar/ExpressionsToSql/Subquery/Items/SubAny.cs
create mode 100644 Src/Asp.Net/SqlSugar/ExpressionsToSql/Subquery/Items/SubBegin'.cs
create mode 100644 Src/Asp.Net/SqlSugar/ExpressionsToSql/Subquery/Items/SubFromTable.cs
create mode 100644 Src/Asp.Net/SqlSugar/ExpressionsToSql/Subquery/Items/SubSelect.cs
create mode 100644 Src/Asp.Net/SqlSugar/ExpressionsToSql/Subquery/Items/SubWhere.cs
create mode 100644 Src/Asp.Net/SqlSugar/ExpressionsToSql/Subquery/Subquerable.cs
diff --git a/Src/Asp.Net/SqlSugar/ExpressionsToSql/DbMethods/SqlFunc.cs b/Src/Asp.Net/SqlSugar/ExpressionsToSql/DbMethods/SqlFunc.cs
index f0a00ccc6..4da350ffe 100644
--- a/Src/Asp.Net/SqlSugar/ExpressionsToSql/DbMethods/SqlFunc.cs
+++ b/Src/Asp.Net/SqlSugar/ExpressionsToSql/DbMethods/SqlFunc.cs
@@ -102,5 +102,11 @@ namespace SqlSugar
///
///
public static TResult GetSelfAndAutoFill(TResult value) { throw new NotSupportedException("Can only be used in expressions"); }
+ ///
+ /// Subquery
+ ///
+ ///
+ ///
+ public static Subqueryable Subqueryable() where T:class,new(){ throw new NotSupportedException("Can only be used in expressions");}
}
}
diff --git a/Src/Asp.Net/SqlSugar/ExpressionsToSql/Subquery/Items/ISubAction.cs b/Src/Asp.Net/SqlSugar/ExpressionsToSql/Subquery/Items/ISubAction.cs
new file mode 100644
index 000000000..42aa2f828
--- /dev/null
+++ b/Src/Asp.Net/SqlSugar/ExpressionsToSql/Subquery/Items/ISubAction.cs
@@ -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; }
+ }
+}
diff --git a/Src/Asp.Net/SqlSugar/ExpressionsToSql/Subquery/Items/SubAny.cs b/Src/Asp.Net/SqlSugar/ExpressionsToSql/Subquery/Items/SubAny.cs
new file mode 100644
index 000000000..6aa2f35fe
--- /dev/null
+++ b/Src/Asp.Net/SqlSugar/ExpressionsToSql/Subquery/Items/SubAny.cs
@@ -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";
+ }
+ }
+}
diff --git a/Src/Asp.Net/SqlSugar/ExpressionsToSql/Subquery/Items/SubBegin'.cs b/Src/Asp.Net/SqlSugar/ExpressionsToSql/Subquery/Items/SubBegin'.cs
new file mode 100644
index 000000000..2b0d2aa65
--- /dev/null
+++ b/Src/Asp.Net/SqlSugar/ExpressionsToSql/Subquery/Items/SubBegin'.cs
@@ -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";
+ }
+ }
+}
diff --git a/Src/Asp.Net/SqlSugar/ExpressionsToSql/Subquery/Items/SubFromTable.cs b/Src/Asp.Net/SqlSugar/ExpressionsToSql/Subquery/Items/SubFromTable.cs
new file mode 100644
index 000000000..bfef1348b
--- /dev/null
+++ b/Src/Asp.Net/SqlSugar/ExpressionsToSql/Subquery/Items/SubFromTable.cs
@@ -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);
+ }
+ }
+}
diff --git a/Src/Asp.Net/SqlSugar/ExpressionsToSql/Subquery/Items/SubSelect.cs b/Src/Asp.Net/SqlSugar/ExpressionsToSql/Subquery/Items/SubSelect.cs
new file mode 100644
index 000000000..38facb47c
--- /dev/null
+++ b/Src/Asp.Net/SqlSugar/ExpressionsToSql/Subquery/Items/SubSelect.cs
@@ -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();
+ }
+ }
+}
diff --git a/Src/Asp.Net/SqlSugar/ExpressionsToSql/Subquery/Items/SubWhere.cs b/Src/Asp.Net/SqlSugar/ExpressionsToSql/Subquery/Items/SubWhere.cs
new file mode 100644
index 000000000..393090e8e
--- /dev/null
+++ b/Src/Asp.Net/SqlSugar/ExpressionsToSql/Subquery/Items/SubWhere.cs
@@ -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();
+ }
+ }
+}
diff --git a/Src/Asp.Net/SqlSugar/ExpressionsToSql/Subquery/Subquerable.cs b/Src/Asp.Net/SqlSugar/ExpressionsToSql/Subquery/Subquerable.cs
new file mode 100644
index 000000000..3fd640cb7
--- /dev/null
+++ b/Src/Asp.Net/SqlSugar/ExpressionsToSql/Subquery/Subquerable.cs
@@ -0,0 +1,39 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Linq.Expressions;
+using System.Text;
+
+namespace SqlSugar
+{
+ ///
+ /// 开发中....
+ ///
+ ///
+ public class Subqueryable where T : class, new()
+ {
+ public Subqueryable Where(Func expression)
+ {
+ return this;
+ }
+
+ public TResult Select(Func expression) where TResult :struct
+ {
+ return default(TResult);
+ }
+ public string Select(Func expression)
+ {
+ return default(string);
+ }
+
+ public bool Any()
+ {
+ return default(bool);
+ }
+
+ public bool Count()
+ {
+ return default(bool);
+ }
+ }
+}
diff --git a/Src/Asp.Net/SqlSugar/SqlSugar.csproj b/Src/Asp.Net/SqlSugar/SqlSugar.csproj
index 947634899..cd36de44b 100644
--- a/Src/Asp.Net/SqlSugar/SqlSugar.csproj
+++ b/Src/Asp.Net/SqlSugar/SqlSugar.csproj
@@ -72,6 +72,13 @@
+
+
+
+
+
+
+