diff --git a/Examples/base_entity/Program.cs b/Examples/base_entity/Program.cs index 9c7fda76..8640cc8e 100644 --- a/Examples/base_entity/Program.cs +++ b/Examples/base_entity/Program.cs @@ -6,6 +6,7 @@ using FreeSql.Internal.Model; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using System; +using System.Collections.Generic; using System.Data.Odbc; using System.Data.SqlClient; using System.Data.SQLite; @@ -87,6 +88,17 @@ namespace base_entity } } + class B + { + public long Id { get; set; } + } + + class A + { + public long BId { get; set; } + public B B { get; set; } + } + static void Main(string[] args) { #region 初始化 IFreeSql @@ -121,10 +133,23 @@ namespace base_entity .UseMonitorCommand(umcmd => Console.WriteLine(umcmd.CommandText)) .UseLazyLoading(true) + .UseGenerateCommandParameterWithLambda(true) .Build(); BaseEntity.Initialization(fsql, () => _asyncUow.Value); #endregion + fsql.UseJsonMap(); + var bid1 = 10; + var list1 = fsql.Select() + .Where(a => a.BId == bid1); + var aid1 = 11; + var select2 = fsql.Select(); + (select2 as Select0Provider)._params = (list1 as Select0Provider)._params; + var list2 = select2 + .Where(a => list1.ToList(B => B.BId).Contains(a.Id)) + .Where(a => a.Id == aid1) + .ToSql(); + //fsql.Aop.CommandBefore += (s, e) => //{ // e.States["xxx"] = 111; diff --git a/FreeSql.DbContext/FreeSql.DbContext.xml b/FreeSql.DbContext/FreeSql.DbContext.xml index 02eb0609..27909b2e 100644 --- a/FreeSql.DbContext/FreeSql.DbContext.xml +++ b/FreeSql.DbContext/FreeSql.DbContext.xml @@ -512,5 +512,14 @@ + + + 批量注入 Repository,可以参考代码自行调整 + + + + + + diff --git a/FreeSql/Extensions/AdoNetExtensions.cs b/FreeSql/Extensions/AdoNetExtensions.cs index f1dc6bf9..3e27483b 100644 --- a/FreeSql/Extensions/AdoNetExtensions.cs +++ b/FreeSql/Extensions/AdoNetExtensions.cs @@ -9,14 +9,15 @@ namespace FreeSql { #region Ado.net 扩展方法,类似于 Dapper - static Dictionary _dicCurd = new Dictionary(); + static Dictionary _dicCurd = new Dictionary(); static object _dicCurdLock = new object(); static IFreeSql GetCrud(IDbConnection dbconn) { if (dbconn == null) throw new ArgumentNullException($"{nameof(dbconn)} 不能为 null"); + if (dbconn.ConnectionString == null) throw new ArgumentNullException($"{nameof(dbconn)}.ConnectionString 不能为 null"); Type dbconType = dbconn.GetType(); var connType = dbconType.UnderlyingSystemType; - if (_dicCurd.TryGetValue(connType, out var fsql)) return fsql; + if (_dicCurd.TryGetValue(dbconn.ConnectionString, out var fsql)) return fsql; Type providerType = null; switch (connType.Name) @@ -63,9 +64,9 @@ namespace FreeSql } lock (_dicCurdLock) { - if (_dicCurd.TryGetValue(connType, out fsql)) return fsql; + if (_dicCurd.TryGetValue(dbconn.ConnectionString, out fsql)) return fsql; lock (_dicCurdLock) - _dicCurd.Add(connType, fsql = Activator.CreateInstance(providerType, new object[] { null, null, null }) as IFreeSql); + _dicCurd.Add(dbconn.ConnectionString, fsql = Activator.CreateInstance(providerType, new object[] { null, null, null }) as IFreeSql); } return fsql; } diff --git a/FreeSql/Internal/CommonProvider/BaseDbProvider.cs b/FreeSql/Internal/CommonProvider/BaseDbProvider.cs index 69077daa..54c76fa5 100644 --- a/FreeSql/Internal/CommonProvider/BaseDbProvider.cs +++ b/FreeSql/Internal/CommonProvider/BaseDbProvider.cs @@ -26,18 +26,18 @@ namespace FreeSql.Internal.CommonProvider public IDelete Delete(object dywhere) where T1 : class => CreateDeleteProvider(dywhere); public IInsertOrUpdate InsertOrUpdate() where T1 : class => CreateInsertOrUpdateProvider(); - public IAdo Ado { get; protected set; } - public IAop Aop { get; protected set; } - public ICodeFirst CodeFirst { get; protected set; } + public virtual IAdo Ado { get; protected set; } + public virtual IAop Aop { get; protected set; } + public virtual ICodeFirst CodeFirst { get; protected set; } public virtual IDbFirst DbFirst { get; protected set; } - public CommonUtils InternalCommonUtils { get; protected set; } - public CommonExpression InternalCommonExpression { get; protected set; } + public virtual CommonUtils InternalCommonUtils { get; protected set; } + public virtual CommonExpression InternalCommonExpression { get; protected set; } public void Transaction(Action handler) => Ado.Transaction(handler); public void Transaction(IsolationLevel isolationLevel, Action handler) => Ado.Transaction(isolationLevel, handler); - public GlobalFilter GlobalFilter { get; } = new GlobalFilter(); + public virtual GlobalFilter GlobalFilter { get; } = new GlobalFilter(); public abstract void Dispose(); } }