mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-04-22 18:52:50 +08:00
- 优化 BaseDbProvider、AdoNetExtensions 内部定义;
This commit is contained in:
parent
1398514a96
commit
054fc4c805
@ -6,6 +6,7 @@ using FreeSql.Internal.Model;
|
|||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Data.Odbc;
|
using System.Data.Odbc;
|
||||||
using System.Data.SqlClient;
|
using System.Data.SqlClient;
|
||||||
using System.Data.SQLite;
|
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)
|
static void Main(string[] args)
|
||||||
{
|
{
|
||||||
#region 初始化 IFreeSql
|
#region 初始化 IFreeSql
|
||||||
@ -121,10 +133,23 @@ namespace base_entity
|
|||||||
|
|
||||||
.UseMonitorCommand(umcmd => Console.WriteLine(umcmd.CommandText))
|
.UseMonitorCommand(umcmd => Console.WriteLine(umcmd.CommandText))
|
||||||
.UseLazyLoading(true)
|
.UseLazyLoading(true)
|
||||||
|
.UseGenerateCommandParameterWithLambda(true)
|
||||||
.Build();
|
.Build();
|
||||||
BaseEntity.Initialization(fsql, () => _asyncUow.Value);
|
BaseEntity.Initialization(fsql, () => _asyncUow.Value);
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
fsql.UseJsonMap();
|
||||||
|
var bid1 = 10;
|
||||||
|
var list1 = fsql.Select<A>()
|
||||||
|
.Where(a => a.BId == bid1);
|
||||||
|
var aid1 = 11;
|
||||||
|
var select2 = fsql.Select<B>();
|
||||||
|
(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) =>
|
//fsql.Aop.CommandBefore += (s, e) =>
|
||||||
//{
|
//{
|
||||||
// e.States["xxx"] = 111;
|
// e.States["xxx"] = 111;
|
||||||
|
@ -512,5 +512,14 @@
|
|||||||
<param name="that"></param>
|
<param name="that"></param>
|
||||||
<returns></returns>
|
<returns></returns>
|
||||||
</member>
|
</member>
|
||||||
|
<member name="M:Microsoft.Extensions.DependencyInjection.FreeSqlRepositoryDependencyInjection.AddFreeRepository(Microsoft.Extensions.DependencyInjection.IServiceCollection,System.Action{FreeSql.FluentDataFilter},System.Reflection.Assembly[])">
|
||||||
|
<summary>
|
||||||
|
批量注入 Repository,可以参考代码自行调整
|
||||||
|
</summary>
|
||||||
|
<param name="services"></param>
|
||||||
|
<param name="globalDataFilter"></param>
|
||||||
|
<param name="assemblies"></param>
|
||||||
|
<returns></returns>
|
||||||
|
</member>
|
||||||
</members>
|
</members>
|
||||||
</doc>
|
</doc>
|
||||||
|
@ -9,14 +9,15 @@ namespace FreeSql
|
|||||||
{
|
{
|
||||||
#region Ado.net 扩展方法,类似于 Dapper
|
#region Ado.net 扩展方法,类似于 Dapper
|
||||||
|
|
||||||
static Dictionary<Type, IFreeSql> _dicCurd = new Dictionary<Type, IFreeSql>();
|
static Dictionary<string, IFreeSql> _dicCurd = new Dictionary<string, IFreeSql>();
|
||||||
static object _dicCurdLock = new object();
|
static object _dicCurdLock = new object();
|
||||||
static IFreeSql GetCrud(IDbConnection dbconn)
|
static IFreeSql GetCrud(IDbConnection dbconn)
|
||||||
{
|
{
|
||||||
if (dbconn == null) throw new ArgumentNullException($"{nameof(dbconn)} 不能为 null");
|
if (dbconn == null) throw new ArgumentNullException($"{nameof(dbconn)} 不能为 null");
|
||||||
|
if (dbconn.ConnectionString == null) throw new ArgumentNullException($"{nameof(dbconn)}.ConnectionString 不能为 null");
|
||||||
Type dbconType = dbconn.GetType();
|
Type dbconType = dbconn.GetType();
|
||||||
var connType = dbconType.UnderlyingSystemType;
|
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;
|
Type providerType = null;
|
||||||
switch (connType.Name)
|
switch (connType.Name)
|
||||||
@ -63,9 +64,9 @@ namespace FreeSql
|
|||||||
}
|
}
|
||||||
lock (_dicCurdLock)
|
lock (_dicCurdLock)
|
||||||
{
|
{
|
||||||
if (_dicCurd.TryGetValue(connType, out fsql)) return fsql;
|
if (_dicCurd.TryGetValue(dbconn.ConnectionString, out fsql)) return fsql;
|
||||||
lock (_dicCurdLock)
|
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;
|
return fsql;
|
||||||
}
|
}
|
||||||
|
@ -26,18 +26,18 @@ namespace FreeSql.Internal.CommonProvider
|
|||||||
public IDelete<T1> Delete<T1>(object dywhere) where T1 : class => CreateDeleteProvider<T1>(dywhere);
|
public IDelete<T1> Delete<T1>(object dywhere) where T1 : class => CreateDeleteProvider<T1>(dywhere);
|
||||||
public IInsertOrUpdate<T1> InsertOrUpdate<T1>() where T1 : class => CreateInsertOrUpdateProvider<T1>();
|
public IInsertOrUpdate<T1> InsertOrUpdate<T1>() where T1 : class => CreateInsertOrUpdateProvider<T1>();
|
||||||
|
|
||||||
public IAdo Ado { get; protected set; }
|
public virtual IAdo Ado { get; protected set; }
|
||||||
public IAop Aop { get; protected set; }
|
public virtual IAop Aop { get; protected set; }
|
||||||
public ICodeFirst CodeFirst { get; protected set; }
|
public virtual ICodeFirst CodeFirst { get; protected set; }
|
||||||
public virtual IDbFirst DbFirst { get; protected set; }
|
public virtual IDbFirst DbFirst { get; protected set; }
|
||||||
|
|
||||||
public CommonUtils InternalCommonUtils { get; protected set; }
|
public virtual CommonUtils InternalCommonUtils { get; protected set; }
|
||||||
public CommonExpression InternalCommonExpression { get; protected set; }
|
public virtual CommonExpression InternalCommonExpression { get; protected set; }
|
||||||
|
|
||||||
public void Transaction(Action handler) => Ado.Transaction(handler);
|
public void Transaction(Action handler) => Ado.Transaction(handler);
|
||||||
public void Transaction(IsolationLevel isolationLevel, Action handler) => Ado.Transaction(isolationLevel, 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();
|
public abstract void Dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user