SqlSugarScopeProvider.cs 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.Diagnostics;
  5. using System.Dynamic;
  6. using System.Linq;
  7. using System.Linq.Expressions;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. namespace SqlSugar
  11. {
  12. public class SqlSugarScopeProvider:ISqlSugarClient
  13. {
  14. internal SqlSugarProvider conn;
  15. StackFrame[] frames;
  16. public SqlSugarScopeProvider(SqlSugarProvider conn)
  17. {
  18. this.conn = conn;
  19. var key = GetKey();
  20. this.GetContext(true);
  21. }
  22. public SqlSugarProvider ScopedContext { get { return GetContext(); } }
  23. private SqlSugarProvider GetAsyncContext(bool isInit=false)
  24. {
  25. if (isInit)
  26. {
  27. CallContextAsync<SqlSugarProvider>.SetData(GetKey(), this.conn);
  28. isInit = false;
  29. return conn;
  30. }
  31. else
  32. {
  33. SqlSugarProvider result = CallContextAsync<SqlSugarProvider>.GetData(GetKey());
  34. if (result == null)
  35. {
  36. SqlSugarProvider db=new SqlSugarProvider(this.conn.CurrentConnectionConfig);
  37. CallContextAsync<SqlSugarProvider>.SetData(GetKey(), db);
  38. return db;
  39. }
  40. else
  41. {
  42. return result;
  43. }
  44. }
  45. }
  46. private SqlSugarProvider GetThreadContext(bool isInit = false)
  47. {
  48. if (isInit)
  49. {
  50. CallContextThread<SqlSugarProvider>.SetData(GetKey(), this.conn);
  51. isInit = false;
  52. return conn;
  53. }
  54. else
  55. {
  56. SqlSugarProvider result = CallContextThread<SqlSugarProvider>.GetData(GetKey());
  57. if (result == null)
  58. {
  59. SqlSugarProvider db = new SqlSugarProvider(this.conn.CurrentConnectionConfig);
  60. CallContextThread<SqlSugarProvider>.SetData(GetKey(), db);
  61. return db;
  62. }
  63. else
  64. {
  65. return result;
  66. }
  67. }
  68. }
  69. protected virtual SqlSugarProvider GetContext(bool isInit = false)
  70. {
  71. SqlSugarProvider result = null;
  72. var key = GetKey(); ;
  73. StackTrace st = new StackTrace(true);
  74. var methods = st.GetFrames();
  75. var isAsync = UtilMethods.IsAnyAsyncMethod(methods);
  76. if (isAsync)
  77. {
  78. result= GetAsyncContext(isInit);
  79. }
  80. else
  81. {
  82. result= GetThreadContext(isInit);
  83. }
  84. return result;
  85. }
  86. private dynamic GetKey()
  87. {
  88. var key= "SqlSugarProviderScope_" + conn.CurrentConnectionConfig.ConfigId;
  89. if (frames == null)
  90. {
  91. frames = new StackTrace(true).GetFrames();
  92. }
  93. if (frames.Length >= 0)
  94. {
  95. foreach (var method in frames.Take(35))
  96. {
  97. var refType = method.GetMethod()?.ReflectedType;
  98. if (refType != null)
  99. {
  100. var getInterfaces = refType.Name.StartsWith("<") ? refType?.ReflectedType?.GetInterfaces() : refType?.GetInterfaces();
  101. if (getInterfaces != null && getInterfaces.Any(it => it.Name.IsIn("IJob")))
  102. {
  103. key = $"{key}IJob";
  104. break;
  105. }
  106. }
  107. }
  108. }
  109. return key;
  110. }
  111. #region API
  112. public Task<SugarAsyncLock> AsyncLock(int timeOutSeconds = 30)
  113. {
  114. return ScopedContext.AsyncLock(timeOutSeconds);
  115. }
  116. public SugarActionType SugarActionType { get => ScopedContext.SugarActionType; set => ScopedContext.SugarActionType = value; }
  117. public MappingTableList MappingTables { get => ScopedContext.MappingTables; set => ScopedContext.MappingTables = value; }
  118. public MappingColumnList MappingColumns { get => ScopedContext.MappingColumns; set => ScopedContext.MappingColumns = value; }
  119. public IgnoreColumnList IgnoreColumns { get => ScopedContext.IgnoreColumns; set => ScopedContext.IgnoreColumns = value; }
  120. public IgnoreColumnList IgnoreInsertColumns { get => ScopedContext.IgnoreInsertColumns; set => ScopedContext.IgnoreInsertColumns = value; }
  121. public Dictionary<string, object> TempItems { get => ScopedContext.TempItems; set => ScopedContext.TempItems = value; }
  122. public ConfigQuery ConfigQuery { get => ScopedContext.ConfigQuery; set => ScopedContext.ConfigQuery = value; }
  123. public bool IsSystemTablesConfig => ScopedContext.IsSystemTablesConfig;
  124. public Guid ContextID { get => ScopedContext.ContextID; set => ScopedContext.ContextID = value; }
  125. public ConnectionConfig CurrentConnectionConfig { get => ScopedContext.CurrentConnectionConfig; set => ScopedContext.CurrentConnectionConfig = value; }
  126. public IAdo Ado => ScopedContext.Ado;
  127. public AopProvider Aop => ScopedContext.Aop;
  128. public ICodeFirst CodeFirst => ScopedContext.CodeFirst;
  129. public IDbFirst DbFirst => ScopedContext.DbFirst;
  130. public IDbMaintenance DbMaintenance => ScopedContext.DbMaintenance;
  131. public EntityMaintenance EntityMaintenance { get => ScopedContext.EntityMaintenance; set => ScopedContext.EntityMaintenance = value; }
  132. public QueryFilterProvider QueryFilter { get => ScopedContext.QueryFilter; set => ScopedContext.QueryFilter = value; }
  133. public IContextMethods Utilities { get => ScopedContext.Utilities; set => ScopedContext.Utilities = value; }
  134. public QueueList Queues { get => ScopedContext.Queues; set => ScopedContext.Queues = value; }
  135. public SugarCacheProvider DataCache => ScopedContext.DataCache;
  136. public void AddQueue(string sql, object parsmeters = null)
  137. {
  138. ScopedContext.AddQueue(sql, parsmeters);
  139. }
  140. public void AddQueue(string sql, List<SugarParameter> parsmeters)
  141. {
  142. ScopedContext.AddQueue(sql, parsmeters);
  143. }
  144. public void AddQueue(string sql, SugarParameter parsmeter)
  145. {
  146. ScopedContext.AddQueue(sql, parsmeter);
  147. }
  148. public void Close()
  149. {
  150. ScopedContext.Close();
  151. }
  152. public DeleteMethodInfo DeleteableByObject(object singleEntityObjectOrListObject)
  153. {
  154. return ScopedContext.DeleteableByObject(singleEntityObjectOrListObject);
  155. }
  156. public IDeleteable<T> Deleteable<T>() where T : class, new()
  157. {
  158. return ScopedContext.Deleteable<T>();
  159. }
  160. public IDeleteable<T> Deleteable<T>(dynamic primaryKeyValue) where T : class, new()
  161. {
  162. return ScopedContext.Deleteable<T>(primaryKeyValue);
  163. }
  164. public IDeleteable<T> Deleteable<T>(dynamic[] primaryKeyValues) where T : class, new()
  165. {
  166. return ScopedContext.Deleteable<T>(primaryKeyValues);
  167. }
  168. public IDeleteable<T> Deleteable<T>(Expression<Func<T, bool>> expression) where T : class, new()
  169. {
  170. return ScopedContext.Deleteable(expression);
  171. }
  172. public IDeleteable<T> Deleteable<T>(List<dynamic> pkValue) where T : class, new()
  173. {
  174. return ScopedContext.Deleteable<T>(pkValue);
  175. }
  176. public IDeleteable<T> Deleteable<T>(List<T> deleteObjs) where T : class, new()
  177. {
  178. return ScopedContext.Deleteable(deleteObjs);
  179. }
  180. public IDeleteable<T> Deleteable<T>(T deleteObj) where T : class, new()
  181. {
  182. return ScopedContext.Deleteable(deleteObj);
  183. }
  184. public void Dispose()
  185. {
  186. ScopedContext.Dispose();
  187. }
  188. public DateTime GetDate()
  189. {
  190. return ScopedContext.GetDate();
  191. }
  192. public T CreateContext<T>(bool isTran) where T : SugarUnitOfWork, new()
  193. {
  194. Check.ExceptionEasy(" var childDb=Db.GetConnection(configId); use Db.CreateContext ", " 例如 var childDb=Db.GetConnection(configId);其中Db才能使用CreateContext,childDb不能使用");
  195. return null;
  196. }
  197. public SugarUnitOfWork CreateContext(bool isTran = true)
  198. {
  199. Check.ExceptionEasy(" var childDb=Db.GetConnection(configId); use Db.CreateContext ", " 例如 var childDb=Db.GetConnection(configId);其中Db才能使用CreateContext,childDb不能使用");
  200. return null;
  201. }
  202. public SimpleClient<T> GetSimpleClient<T>() where T : class, new()
  203. {
  204. return ScopedContext.GetSimpleClient<T>();
  205. }
  206. public RepositoryType GetRepository<RepositoryType>() where RepositoryType : ISugarRepository, new()
  207. {
  208. return ScopedContext.GetRepository<RepositoryType>();
  209. }
  210. public void InitMappingInfo(Type type)
  211. {
  212. ScopedContext.InitMappingInfo(type);
  213. }
  214. public void InitMappingInfo<T>()
  215. {
  216. ScopedContext.InitMappingInfo<T>();
  217. }
  218. public IInsertable<Dictionary<string, object>> InsertableByDynamic(object insertDynamicObject)
  219. {
  220. return ScopedContext.InsertableByDynamic(insertDynamicObject);
  221. }
  222. public InsertMethodInfo InsertableByObject(object singleEntityObjectOrListObject)
  223. {
  224. return ScopedContext.InsertableByObject(singleEntityObjectOrListObject);
  225. }
  226. public IInsertable<T> Insertable<T>(Dictionary<string, object> columnDictionary) where T : class, new()
  227. {
  228. return ScopedContext.Insertable<T>(columnDictionary);
  229. }
  230. public IInsertable<T> Insertable<T>(dynamic insertDynamicObject) where T : class, new()
  231. {
  232. return ScopedContext.Insertable<T>((object)insertDynamicObject);
  233. }
  234. public IInsertable<T> Insertable<T>(List<T> insertObjs) where T : class, new()
  235. {
  236. return ScopedContext.Insertable(insertObjs);
  237. }
  238. public IInsertable<T> Insertable<T>(T insertObj) where T : class, new()
  239. {
  240. return ScopedContext.Insertable(insertObj);
  241. }
  242. public IInsertable<T> Insertable<T>(T[] insertObjs) where T : class, new()
  243. {
  244. return ScopedContext.Insertable(insertObjs);
  245. }
  246. public void Open()
  247. {
  248. ScopedContext.Open();
  249. }
  250. public ISugarQueryable<T> SlaveQueryable<T>()
  251. {
  252. return ScopedContext.SlaveQueryable<T>();
  253. }
  254. public ISugarQueryable<T> MasterQueryable<T>()
  255. {
  256. return ScopedContext.MasterQueryable<T>();
  257. }
  258. public ISugarQueryable<ExpandoObject> Queryable(string tableName, string shortName)
  259. {
  260. return ScopedContext.Queryable(tableName, shortName);
  261. }
  262. public ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12> Queryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>(Expression<Func<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, bool>> joinExpression) where T : class, new()
  263. {
  264. return ScopedContext.Queryable(joinExpression);
  265. }
  266. public ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12> Queryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>(Expression<Func<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, JoinQueryInfos>> joinExpression)
  267. {
  268. return ScopedContext.Queryable(joinExpression);
  269. }
  270. public ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12> Queryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>(Expression<Func<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, object[]>> joinExpression)
  271. {
  272. return ScopedContext.Queryable(joinExpression);
  273. }
  274. public ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11> Queryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>(Expression<Func<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, bool>> joinExpression) where T : class, new()
  275. {
  276. return ScopedContext.Queryable(joinExpression);
  277. }
  278. public ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11> Queryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>(Expression<Func<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, JoinQueryInfos>> joinExpression)
  279. {
  280. return ScopedContext.Queryable(joinExpression);
  281. }
  282. public ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11> Queryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>(Expression<Func<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, object[]>> joinExpression)
  283. {
  284. return ScopedContext.Queryable(joinExpression);
  285. }
  286. public ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10> Queryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10>(Expression<Func<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, bool>> joinExpression) where T : class, new()
  287. {
  288. return ScopedContext.Queryable(joinExpression);
  289. }
  290. public ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10> Queryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10>(Expression<Func<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, JoinQueryInfos>> joinExpression)
  291. {
  292. return ScopedContext.Queryable(joinExpression);
  293. }
  294. public ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10> Queryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10>(Expression<Func<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, object[]>> joinExpression)
  295. {
  296. return ScopedContext.Queryable(joinExpression);
  297. }
  298. public ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9> Queryable<T, T2, T3, T4, T5, T6, T7, T8, T9>(Expression<Func<T, T2, T3, T4, T5, T6, T7, T8, T9, bool>> joinExpression) where T : class, new()
  299. {
  300. return ScopedContext.Queryable(joinExpression);
  301. }
  302. public ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9> Queryable<T, T2, T3, T4, T5, T6, T7, T8, T9>(Expression<Func<T, T2, T3, T4, T5, T6, T7, T8, T9, JoinQueryInfos>> joinExpression)
  303. {
  304. return ScopedContext.Queryable(joinExpression);
  305. }
  306. public ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9> Queryable<T, T2, T3, T4, T5, T6, T7, T8, T9>(Expression<Func<T, T2, T3, T4, T5, T6, T7, T8, T9, object[]>> joinExpression)
  307. {
  308. return ScopedContext.Queryable(joinExpression);
  309. }
  310. public ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8> Queryable<T, T2, T3, T4, T5, T6, T7, T8>(Expression<Func<T, T2, T3, T4, T5, T6, T7, T8, bool>> joinExpression) where T : class, new()
  311. {
  312. return ScopedContext.Queryable(joinExpression);
  313. }
  314. public ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8> Queryable<T, T2, T3, T4, T5, T6, T7, T8>(Expression<Func<T, T2, T3, T4, T5, T6, T7, T8, JoinQueryInfos>> joinExpression)
  315. {
  316. return ScopedContext.Queryable(joinExpression);
  317. }
  318. public ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8> Queryable<T, T2, T3, T4, T5, T6, T7, T8>(Expression<Func<T, T2, T3, T4, T5, T6, T7, T8, object[]>> joinExpression)
  319. {
  320. return ScopedContext.Queryable(joinExpression);
  321. }
  322. public ISugarQueryable<T, T2, T3, T4, T5, T6, T7> Queryable<T, T2, T3, T4, T5, T6, T7>(Expression<Func<T, T2, T3, T4, T5, T6, T7, bool>> joinExpression) where T : class, new()
  323. {
  324. return ScopedContext.Queryable(joinExpression);
  325. }
  326. public ISugarQueryable<T, T2, T3, T4, T5, T6, T7> Queryable<T, T2, T3, T4, T5, T6, T7>(Expression<Func<T, T2, T3, T4, T5, T6, T7, JoinQueryInfos>> joinExpression)
  327. {
  328. return ScopedContext.Queryable(joinExpression);
  329. }
  330. public ISugarQueryable<T, T2, T3, T4, T5, T6, T7> Queryable<T, T2, T3, T4, T5, T6, T7>(Expression<Func<T, T2, T3, T4, T5, T6, T7, object[]>> joinExpression)
  331. {
  332. return ScopedContext.Queryable(joinExpression);
  333. }
  334. public ISugarQueryable<T, T2, T3, T4, T5, T6> Queryable<T, T2, T3, T4, T5, T6>(Expression<Func<T, T2, T3, T4, T5, T6, bool>> joinExpression) where T : class, new()
  335. {
  336. return ScopedContext.Queryable(joinExpression);
  337. }
  338. public ISugarQueryable<T, T2, T3, T4, T5, T6> Queryable<T, T2, T3, T4, T5, T6>(Expression<Func<T, T2, T3, T4, T5, T6, JoinQueryInfos>> joinExpression)
  339. {
  340. return ScopedContext.Queryable(joinExpression);
  341. }
  342. public ISugarQueryable<T, T2, T3, T4, T5, T6> Queryable<T, T2, T3, T4, T5, T6>(Expression<Func<T, T2, T3, T4, T5, T6, object[]>> joinExpression)
  343. {
  344. return ScopedContext.Queryable(joinExpression);
  345. }
  346. public ISugarQueryable<T, T2, T3, T4, T5> Queryable<T, T2, T3, T4, T5>(Expression<Func<T, T2, T3, T4, T5, bool>> joinExpression) where T : class, new()
  347. {
  348. return ScopedContext.Queryable(joinExpression);
  349. }
  350. public ISugarQueryable<T, T2, T3, T4, T5> Queryable<T, T2, T3, T4, T5>(Expression<Func<T, T2, T3, T4, T5, JoinQueryInfos>> joinExpression)
  351. {
  352. return ScopedContext.Queryable(joinExpression);
  353. }
  354. public ISugarQueryable<T, T2, T3, T4, T5> Queryable<T, T2, T3, T4, T5>(Expression<Func<T, T2, T3, T4, T5, object[]>> joinExpression)
  355. {
  356. return ScopedContext.Queryable(joinExpression);
  357. }
  358. public ISugarQueryable<T, T2, T3, T4> Queryable<T, T2, T3, T4>(Expression<Func<T, T2, T3, T4, bool>> joinExpression) where T : class, new()
  359. {
  360. return ScopedContext.Queryable(joinExpression);
  361. }
  362. public ISugarQueryable<T, T2, T3, T4> Queryable<T, T2, T3, T4>(Expression<Func<T, T2, T3, T4, JoinQueryInfos>> joinExpression)
  363. {
  364. return ScopedContext.Queryable(joinExpression);
  365. }
  366. public ISugarQueryable<T, T2, T3, T4> Queryable<T, T2, T3, T4>(Expression<Func<T, T2, T3, T4, object[]>> joinExpression)
  367. {
  368. return ScopedContext.Queryable(joinExpression);
  369. }
  370. public ISugarQueryable<T, T2, T3> Queryable<T, T2, T3>(Expression<Func<T, T2, T3, bool>> joinExpression) where T : class, new()
  371. {
  372. return ScopedContext.Queryable(joinExpression);
  373. }
  374. public ISugarQueryable<T, T2, T3> Queryable<T, T2, T3>(Expression<Func<T, T2, T3, JoinQueryInfos>> joinExpression)
  375. {
  376. return ScopedContext.Queryable(joinExpression);
  377. }
  378. public ISugarQueryable<T, T2, T3> Queryable<T, T2, T3>(Expression<Func<T, T2, T3, object[]>> joinExpression)
  379. {
  380. return ScopedContext.Queryable(joinExpression);
  381. }
  382. public ISugarQueryable<T, T2> Queryable<T, T2>(Expression<Func<T, T2, bool>> joinExpression) where T : class, new()
  383. {
  384. return ScopedContext.Queryable(joinExpression);
  385. }
  386. public ISugarQueryable<T, T2> Queryable<T, T2>(Expression<Func<T, T2, JoinQueryInfos>> joinExpression)
  387. {
  388. return ScopedContext.Queryable(joinExpression);
  389. }
  390. public ISugarQueryable<T, T2> Queryable<T, T2>(Expression<Func<T, T2, object[]>> joinExpression)
  391. {
  392. return ScopedContext.Queryable(joinExpression);
  393. }
  394. public ISugarQueryable<T, T2> Queryable<T, T2>(ISugarQueryable<T> joinQueryable1, ISugarQueryable<T2> joinQueryable2, Expression<Func<T, T2, bool>> joinExpression)
  395. where T : class, new()
  396. where T2 : class, new()
  397. {
  398. return ScopedContext.Queryable(joinQueryable1, joinQueryable2, joinExpression);
  399. }
  400. public ISugarQueryable<T, T2> Queryable<T, T2>(ISugarQueryable<T> joinQueryable1, ISugarQueryable<T2> joinQueryable2, JoinType joinType, Expression<Func<T, T2, bool>> joinExpression)
  401. where T : class, new()
  402. where T2 : class, new()
  403. {
  404. return ScopedContext.Queryable(joinQueryable1, joinQueryable2, joinType, joinExpression);
  405. }
  406. public ISugarQueryable<T, T2, T3> Queryable<T, T2, T3>(ISugarQueryable<T> joinQueryable1, ISugarQueryable<T2> joinQueryable2, ISugarQueryable<T3> joinQueryable3, JoinType joinType1, Expression<Func<T, T2, T3, bool>> joinExpression1, JoinType joinType2, Expression<Func<T, T2, T3, bool>> joinExpression2)
  407. where T : class, new()
  408. where T2 : class, new()
  409. where T3 : class, new()
  410. {
  411. return ScopedContext.Queryable(joinQueryable1, joinQueryable2, joinQueryable3, joinType1, joinExpression1, joinType2, joinExpression2);
  412. }
  413. public ISugarQueryable<T, T2, T3, T4> Queryable<T, T2, T3, T4>(ISugarQueryable<T> joinQueryable1, ISugarQueryable<T2> joinQueryable2, ISugarQueryable<T3> joinQueryable3, ISugarQueryable<T4> joinQueryable4, JoinType joinType1, Expression<Func<T, T2, T3, T4, bool>> joinExpression1, JoinType joinType2, Expression<Func<T, T2, T3, T4, bool>> joinExpression2, JoinType joinType3, Expression<Func<T, T2, T3, T4, bool>> joinExpression3)
  414. where T : class, new()
  415. where T2 : class, new()
  416. where T3 : class, new()
  417. where T4 : class, new()
  418. {
  419. return ScopedContext.Queryable(joinQueryable1, joinQueryable2, joinQueryable3, joinQueryable4, joinType1, joinExpression1, joinType2, joinExpression2, joinType3, joinExpression3);
  420. }
  421. public ISugarQueryable<T> Queryable<T>()
  422. {
  423. return ScopedContext.Queryable<T>();
  424. }
  425. public ISugarQueryable<T> Queryable<T>(ISugarQueryable<T> queryable)
  426. {
  427. return ScopedContext.Queryable(queryable);
  428. }
  429. public ISugarQueryable<T> Queryable<T>(ISugarQueryable<T> queryable, string shortName)
  430. {
  431. return ScopedContext.Queryable(queryable, shortName);
  432. }
  433. public ISugarQueryable<T> Queryable<T>(string shortName)
  434. {
  435. return ScopedContext.Queryable<T>(shortName);
  436. }
  437. public IReportable<T> Reportable<T>(T data)
  438. {
  439. return ScopedContext.Reportable(data);
  440. }
  441. public IReportable<T> Reportable<T>(List<T> list)
  442. {
  443. return ScopedContext.Reportable(list);
  444. }
  445. public IReportable<T> Reportable<T>(T[] array)
  446. {
  447. return ScopedContext.Reportable(array);
  448. }
  449. public int SaveQueues(bool isTran = true)
  450. {
  451. return ScopedContext.SaveQueues(isTran);
  452. }
  453. public Tuple<List<T>, List<T2>, List<T3>, List<T4>, List<T5>, List<T6>, List<T7>> SaveQueues<T, T2, T3, T4, T5, T6, T7>(bool isTran = true)
  454. {
  455. return ScopedContext.SaveQueues<T, T2, T3, T4, T5, T6, T7>(isTran);
  456. }
  457. public Tuple<List<T>, List<T2>, List<T3>, List<T4>, List<T5>, List<T6>> SaveQueues<T, T2, T3, T4, T5, T6>(bool isTran = true)
  458. {
  459. return ScopedContext.SaveQueues<T, T2, T3, T4, T5, T6>(isTran);
  460. }
  461. public Tuple<List<T>, List<T2>, List<T3>, List<T4>, List<T5>> SaveQueues<T, T2, T3, T4, T5>(bool isTran = true)
  462. {
  463. return ScopedContext.SaveQueues<T, T2, T3, T4, T5>(isTran);
  464. }
  465. public Tuple<List<T>, List<T2>, List<T3>, List<T4>> SaveQueues<T, T2, T3, T4>(bool isTran = true)
  466. {
  467. return ScopedContext.SaveQueues<T, T2, T3, T4>(isTran);
  468. }
  469. public Tuple<List<T>, List<T2>, List<T3>> SaveQueues<T, T2, T3>(bool isTran = true)
  470. {
  471. return ScopedContext.SaveQueues<T, T2, T3>(isTran);
  472. }
  473. public Tuple<List<T>, List<T2>> SaveQueues<T, T2>(bool isTran = true)
  474. {
  475. return ScopedContext.SaveQueues<T, T2>(isTran);
  476. }
  477. public List<T> SaveQueues<T>(bool isTran = true)
  478. {
  479. return ScopedContext.SaveQueues<T>(isTran);
  480. }
  481. public Task<int> SaveQueuesAsync(bool isTran = true)
  482. {
  483. return ScopedContext.SaveQueuesAsync(isTran);
  484. }
  485. public Task<Tuple<List<T>, List<T2>, List<T3>, List<T4>, List<T5>, List<T6>, List<T7>>> SaveQueuesAsync<T, T2, T3, T4, T5, T6, T7>(bool isTran = true)
  486. {
  487. return ScopedContext.SaveQueuesAsync<T, T2, T3, T4, T5, T6, T7>(isTran);
  488. }
  489. public Task<Tuple<List<T>, List<T2>, List<T3>, List<T4>, List<T5>, List<T6>>> SaveQueuesAsync<T, T2, T3, T4, T5, T6>(bool isTran = true)
  490. {
  491. return ScopedContext.SaveQueuesAsync<T, T2, T3, T4, T5, T6>(isTran);
  492. }
  493. public Task<Tuple<List<T>, List<T2>, List<T3>, List<T4>, List<T5>>> SaveQueuesAsync<T, T2, T3, T4, T5>(bool isTran = true)
  494. {
  495. return ScopedContext.SaveQueuesAsync<T, T2, T3, T4, T5>(isTran);
  496. }
  497. public Task<Tuple<List<T>, List<T2>, List<T3>, List<T4>>> SaveQueuesAsync<T, T2, T3, T4>(bool isTran = true)
  498. {
  499. return ScopedContext.SaveQueuesAsync<T, T2, T3, T4>(isTran);
  500. }
  501. public Task<Tuple<List<T>, List<T2>, List<T3>>> SaveQueuesAsync<T, T2, T3>(bool isTran = true)
  502. {
  503. return ScopedContext.SaveQueuesAsync<T, T2, T3>(isTran);
  504. }
  505. public Task<Tuple<List<T>, List<T2>>> SaveQueuesAsync<T, T2>(bool isTran = true)
  506. {
  507. return ScopedContext.SaveQueuesAsync<T, T2>(isTran);
  508. }
  509. public Task<List<T>> SaveQueuesAsync<T>(bool isTran = true)
  510. {
  511. return ScopedContext.SaveQueuesAsync<T>(isTran);
  512. }
  513. public ISugarQueryable<T> SqlQueryable<T>(string sql) where T : class, new()
  514. {
  515. return ScopedContext.SqlQueryable<T>(sql);
  516. }
  517. public IStorageable<T> Storageable<T>(T[] dataList) where T : class, new()
  518. {
  519. return ScopedContext.Storageable(dataList);
  520. }
  521. public StorageableDataTable Storageable(List<Dictionary<string, object>> dictionaryList, string tableName)
  522. {
  523. return ScopedContext.Storageable(dictionaryList, tableName);
  524. }
  525. public StorageableDataTable Storageable(Dictionary<string, object> dictionary, string tableName)
  526. {
  527. return ScopedContext.Storageable(dictionary, tableName);
  528. }
  529. public IStorageable<T> Storageable<T>(List<T> dataList) where T : class, new()
  530. {
  531. return ScopedContext.Storageable(dataList);
  532. }
  533. public IStorageable<T> Storageable<T>(IList<T> dataList) where T : class, new()
  534. {
  535. return ScopedContext.Storageable(dataList?.ToList());
  536. }
  537. public IStorageable<T> Storageable<T>(T data) where T : class, new()
  538. {
  539. return ScopedContext.Storageable(data);
  540. }
  541. public StorageableDataTable Storageable(DataTable data)
  542. {
  543. return ScopedContext.Storageable(data);
  544. }
  545. public StorageableMethodInfo StorageableByObject(object singleEntityObjectOrListObject)
  546. {
  547. return ScopedContext.StorageableByObject(singleEntityObjectOrListObject);
  548. }
  549. public ISugarQueryable<T> Union<T>(List<ISugarQueryable<T>> queryables) where T : class, new()
  550. {
  551. return ScopedContext.Union(queryables);
  552. }
  553. public ISugarQueryable<T> Union<T>(params ISugarQueryable<T>[] queryables) where T : class, new()
  554. {
  555. return ScopedContext.Union(queryables);
  556. }
  557. public ISugarQueryable<T> UnionAll<T>(List<ISugarQueryable<T>> queryables) where T : class, new()
  558. {
  559. return ScopedContext.UnionAll(queryables);
  560. }
  561. public ISugarQueryable<T> UnionAll<T>(params ISugarQueryable<T>[] queryables) where T : class, new()
  562. {
  563. return ScopedContext.UnionAll(queryables);
  564. }
  565. public UpdateExpressionMethodInfo UpdateableByObject(Type entityType)
  566. {
  567. return ScopedContext.UpdateableByObject(entityType);
  568. }
  569. public UpdateMethodInfo UpdateableByObject(object singleEntityObjectOrListObject)
  570. {
  571. return ScopedContext.UpdateableByObject(singleEntityObjectOrListObject);
  572. }
  573. public IUpdateable<Dictionary<string, object>> UpdateableByDynamic(object updateDynamicObject)
  574. {
  575. return ScopedContext.UpdateableByDynamic(updateDynamicObject);
  576. }
  577. public IUpdateable<T> Updateable<T>() where T : class, new()
  578. {
  579. return ScopedContext.Updateable<T>();
  580. }
  581. public IUpdateable<T> Updateable<T>(Dictionary<string, object> columnDictionary) where T : class, new()
  582. {
  583. return ScopedContext.Updateable<T>(columnDictionary);
  584. }
  585. public IUpdateable<T> Updateable<T>(dynamic updateDynamicObject) where T : class, new()
  586. {
  587. return ScopedContext.Updateable<T>((object)updateDynamicObject);
  588. }
  589. public IUpdateable<T> Updateable<T>(Expression<Func<T, bool>> columns) where T : class, new()
  590. {
  591. return ScopedContext.Updateable(columns);
  592. }
  593. public IUpdateable<T> Updateable<T>(Expression<Func<T, T>> columns) where T : class, new()
  594. {
  595. return ScopedContext.Updateable(columns);
  596. }
  597. public IUpdateable<T> Updateable<T>(List<T> UpdateObjs) where T : class, new()
  598. {
  599. return ScopedContext.Updateable(UpdateObjs);
  600. }
  601. public IUpdateable<T> Updateable<T>(T UpdateObj) where T : class, new()
  602. {
  603. return ScopedContext.Updateable(UpdateObj);
  604. }
  605. public IUpdateable<T> Updateable<T>(T[] UpdateObjs) where T : class, new()
  606. {
  607. return ScopedContext.Updateable(UpdateObjs);
  608. }
  609. public SplitTableContext SplitHelper<T>() where T : class, new()
  610. {
  611. return ScopedContext.SplitHelper<T>();
  612. }
  613. public SplitTableContext SplitHelper(Type entityType)
  614. {
  615. return ScopedContext.SplitHelper(entityType);
  616. }
  617. public SplitTableContextResult<T> SplitHelper<T>(T data) where T : class, new()
  618. {
  619. return ScopedContext.SplitHelper(data);
  620. }
  621. public SplitTableContextResult<T> SplitHelper<T>(List<T> dataList) where T : class, new()
  622. {
  623. return ScopedContext.SplitHelper(dataList);
  624. }
  625. public IFastest<T> Fastest<T>() where T : class, new()
  626. {
  627. return ScopedContext.Fastest<T>();
  628. }
  629. public void ThenMapper<T>(IEnumerable<T> list, Action<T> action)
  630. {
  631. ScopedContext.ThenMapper(list, action);
  632. }
  633. public Task ThenMapperAsync<T>(IEnumerable<T> list, Func<T, Task> action)
  634. {
  635. return ScopedContext.ThenMapperAsync(list, action);
  636. }
  637. public ITenant AsTenant()
  638. {
  639. return ScopedContext.AsTenant();
  640. }
  641. public ISaveable<T> Saveable<T>(List<T> saveObjects) where T : class, new()
  642. {
  643. return ScopedContext.Saveable(saveObjects);
  644. }
  645. public ISaveable<T> Saveable<T>(T saveObject) where T : class, new()
  646. {
  647. return ScopedContext.Saveable(saveObject);
  648. }
  649. public InsertNavTaskInit<T, T> InsertNav<T>(T data) where T : class, new()
  650. {
  651. return ScopedContext.InsertNav(data);
  652. }
  653. public InsertNavTaskInit<T, T> InsertNav<T>(List<T> datas) where T : class, new()
  654. {
  655. return ScopedContext.InsertNav(datas);
  656. }
  657. public InsertNavTaskInit<T, T> InsertNav<T>(T data,InsertNavRootOptions rootOptions) where T : class, new()
  658. {
  659. return ScopedContext.InsertNav(data,rootOptions);
  660. }
  661. public InsertNavTaskInit<T, T> InsertNav<T>(List<T> datas, InsertNavRootOptions rootOptions) where T : class, new()
  662. {
  663. return ScopedContext.InsertNav(datas,rootOptions);
  664. }
  665. public DeleteNavTaskInit<T, T> DeleteNav<T>(T data) where T : class, new()
  666. {
  667. return ScopedContext.DeleteNav(data);
  668. }
  669. public DeleteNavTaskInit<T, T> DeleteNav<T>(List<T> datas) where T : class, new()
  670. {
  671. return ScopedContext.DeleteNav(datas);
  672. }
  673. public DeleteNavTaskInit<T, T> DeleteNav<T>(Expression<Func<T, bool>> whereExpression) where T : class, new()
  674. {
  675. return ScopedContext.DeleteNav(whereExpression);
  676. }
  677. public DeleteNavTaskInit<T, T> DeleteNav<T>(T data, DeleteNavRootOptions options) where T : class, new()
  678. {
  679. return ScopedContext.DeleteNav(data, options);
  680. }
  681. public DeleteNavTaskInit<T, T> DeleteNav<T>(List<T> datas, DeleteNavRootOptions options) where T : class, new()
  682. {
  683. return ScopedContext.DeleteNav(datas, options);
  684. }
  685. public DeleteNavTaskInit<T, T> DeleteNav<T>(Expression<Func<T, bool>> whereExpression, DeleteNavRootOptions options) where T : class, new()
  686. {
  687. return ScopedContext.DeleteNav(whereExpression, options);
  688. }
  689. public UpdateNavTaskInit<T, T> UpdateNav<T>(T data) where T : class, new()
  690. {
  691. return ScopedContext.UpdateNav(data);
  692. }
  693. public UpdateNavTaskInit<T, T> UpdateNav<T>(List<T> datas) where T : class, new()
  694. {
  695. return ScopedContext.UpdateNav(datas);
  696. }
  697. public UpdateNavTaskInit<T, T> UpdateNav<T>(List<T> datas, UpdateNavRootOptions rootOptions) where T : class, new()
  698. {
  699. return this.ScopedContext.UpdateNav(datas, rootOptions);
  700. }
  701. public UpdateNavTaskInit<T, T> UpdateNav<T>(T data, UpdateNavRootOptions rootOptions) where T : class, new()
  702. {
  703. return this.ScopedContext.UpdateNav(data, rootOptions);
  704. }
  705. public SqlSugarClient CopyNew()
  706. {
  707. var result= new SqlSugarClient(UtilMethods.CopyConfig(this.Ado.Context.CurrentConnectionConfig));
  708. result.QueryFilter = this.QueryFilter;
  709. return result;
  710. }
  711. public DynamicBuilder DynamicBuilder()
  712. {
  713. return ScopedContext.DynamicBuilder();
  714. }
  715. public void Tracking<T>(T data) where T : class, new()
  716. {
  717. ScopedContext.Tracking(data);
  718. }
  719. public void Tracking<T>(List<T> datas) where T : class, new()
  720. {
  721. ScopedContext.Tracking(datas);
  722. }
  723. public QueryMethodInfo QueryableByObject(Type entityType)
  724. {
  725. return ScopedContext.QueryableByObject(entityType);
  726. }
  727. public QueryMethodInfo QueryableByObject(Type entityType, string shortName)
  728. {
  729. return ScopedContext.QueryableByObject(entityType, shortName);
  730. }
  731. public GridSaveProvider<T> GridSave<T>(List<T> oldList, List<T> saveList) where T : class, new()
  732. {
  733. return ScopedContext.GridSave(oldList, saveList);
  734. }
  735. public GridSaveProvider<T> GridSave<T>(List<T> saveList) where T : class, new()
  736. {
  737. return ScopedContext.GridSave(saveList);
  738. }
  739. public void ClearTracking()
  740. {
  741. ScopedContext.ClearTracking();
  742. }
  743. #endregion
  744. }
  745. }