From c89e4f9b20c681ba46c5c057c2909d6a6612d24a Mon Sep 17 00:00:00 2001
From: 28810 <28810@YEXIANGQIN>
Date: Mon, 20 Jan 2020 01:48:41 +0800
Subject: [PATCH] debug #183
---
FreeSql/FreeSql.xml | 432 +++++++++---------
.../FreeSql.Provider.Sqlite/AdonetPortable.cs | 61 ---
.../FreeSql.Provider.Sqlite.csproj | 7 +-
.../SqliteAdo/SqliteAdo.cs | 9 +-
.../SqliteAdo/SqliteConnectionPool.cs | 5 +-
.../FreeSql.Provider.Sqlite/SqliteProvider.cs | 1 +
.../FreeSql.Provider.Sqlite/SqliteUtils.cs | 5 +-
7 files changed, 237 insertions(+), 283 deletions(-)
delete mode 100644 Providers/FreeSql.Provider.Sqlite/AdonetPortable.cs
diff --git a/FreeSql/FreeSql.xml b/FreeSql/FreeSql.xml
index 59e0a2ec..df8d2443 100644
--- a/FreeSql/FreeSql.xml
+++ b/FreeSql/FreeSql.xml
@@ -2546,159 +2546,7 @@
耗时(单位:Ticks)
-
-
- 耗时(单位:毫秒)
-
-
-
-
- 类型
-
-
-
-
- 属性列的元数据
-
-
-
-
- 反射的属性信息
-
-
-
-
- 获取实体的属性值,也可以设置实体的属性新值
-
-
-
-
- 【开发环境必备】自动同步实体结构到数据库,程序运行中检查实体表是否存在,然后创建或修改
-
-
-
-
- 转小写同步结构
-
-
-
-
- 转大写同步结构
-
-
-
-
- 将数据库的主键、自增、索引设置导入,适用 DbFirst 模式,无须在实体类型上设置 [Column(IsPrimary)] 或者 ConfigEntity。此功能目前可用于 mysql/sqlserver/postgresql/oracle。
- 本功能会影响 IFreeSql 首次访问的速度。
- 若使用 CodeFirst 创建索引后,又直接在数据库上建了索引,若无本功能下一次 CodeFirst 迁移时数据库上创建的索引将被删除
-
-
-
-
- 不使用命令参数化执行,针对 Insert/Update
-
-
-
-
- 是否生成命令参数化执行,针对 lambda 表达式解析
-
-
-
-
- 延时加载导航属性对象,导航属性需要声明 virtual
-
-
-
-
- 将实体类型与数据库对比,返回DDL语句
-
-
-
-
-
-
- 将实体类型集合与数据库对比,返回DDL语句
-
- 实体类型
-
-
-
-
- 将实体类型与数据库对比,返回DDL语句(指定表名)
-
- 实体类型
- 指定表名对比
-
-
-
-
- 同步实体类型到数据库
-
-
-
-
-
-
- 同步实体类型集合到数据库
-
-
-
-
-
-
- 同步实体类型到数据库(指定表名)
-
- 实体类型
- 指定表名对比
-
-
-
-
- 根据 System.Type 获取数据库信息
-
-
-
-
-
-
- 在外部配置实体的特性
-
-
-
-
-
-
-
- 在外部配置实体的特性
-
-
-
-
-
-
-
- 获取在外部配置实体的特性
-
-
- 未使用ConfigEntity配置时,返回null
-
-
-
- 获取实体类核心配置
-
-
-
-
-
-
- 获取所有数据库
-
-
-
-
-
- 获取指定数据库的表信息,包括表、列详情、主键、唯一键、索引、外键、备注
-
+
@@ -2887,98 +2735,107 @@
C#:从元组集合中查找 exp1, exp2, exp2 是否存在
SQL:
exp1 = that[0].Item1 and exp2 = that[0].Item2 and exp3 = that[0].Item3 OR
- exp1 = that[1].Item1 and exp2 = that[1].Item2 and exp3 = that[1].Item3 OR
- ...
- 注意:当 that 为 null 或 empty 时,返回 1=0
+ exp1 = that[1].Item1 and exp2 = that[1].Item2 aummary>
+ 获取ado.net读取方法, GetBoolean、GetInt64
-
-
-
-
-
-
-
+
-
+
- 测量两个经纬度的距离,返回单位:米
+ 序列化
- 经纬坐标1
- 经纬坐标2
- 返回距离(单位:米)
+
+
-
+
- 将 IEnumable<T> 转成 ISelect<T>,以便使用 FreeSql 的查询功能。此方法用于 Lambad 表达式中,快速进行集合导航的查询。
+ 反序列化
+
+
+
+
+
+
+ 获取数据库枚举类型,适用 PostgreSQL
+
+
+
+
+
+
+ AsType, Ctor, ClearData 三处地方需要重新加载
+
+
+
+
+ AsType, Ctor, ClearData 三处地方需要重新加载
+
+
+
+
+ 通过属性的注释文本,通过 xml 读取
+
+
+ Dict:key=属性名,value=注释
+
+
+
+ 创建一个过滤器
-
+ 名字
+ 表达式
-
+
- 多表查询
+ 中间表,多对多
-
-
+
- 多表查询
+ 不进行任何处理
-
-
+
- 多表查询
+ 将帕斯卡命名字符串转换为下划线分隔字符串
+
+ BigApple -> Big_Apple
-
-
+
- 多表查询
+ 将帕斯卡命名字符串转换为下划线分隔字符串,且转换为全大写
+
+ BigApple -> BIG_APPLE
-
-
+
- 多表查询
+ 将帕斯卡命名字符串转换为下划线分隔字符串,且转换为全小写
+
+ BigApple -> big_apple
-
-
+
- 多表查询
+ 将字符串转换为大写
+
+ BigApple -> BIGAPPLE
-
-
+
- 多表查询
+ 将字符串转换为小写
+
+ BigApple -> bigapple
-
-
+
- 多表查询
-
-
-
-
-
- 多表查询
-
-
-
-
-
- 本方法实现从已知的内存 List 数据,进行和 ISelect.IncludeMany 相同功能的贪婪加载
- 示例:new List<Song>(new[] { song1, song2, song3 }).IncludeMany(g.sqlite, a => a.Tags);
- 文档:https://github.com/2881099/FreeSql/wiki/%e8%b4%aa%e5%a9%aa%e5%8a%a0%e8%bd%bd#%E5%AF%BC%E8%88%AA%E5%B1%9E%E6%80%A7-onetomanymanytomany
-
-
- 选择一个集合的导航属性,如: .IncludeMany(a => a.Tags)
- 可以 .Where 设置临时的关系映射,如: .IncludeMany(a => a.Tags.Where(tag => tag.TypeId == a.Id))
+ 将帕斯系映射,如: .IncludeMany(a => a.Tags.Where(tag => tag.TypeId == a.Id))
可以 .Take(5) 每个子集合只取5条,如: .IncludeMany(a => a.Tags.Take(5))
可以 .Select 设置只查询部分字段,如: (a => new TNavigate { Title = a.Title })
@@ -3152,6 +3009,157 @@
CodeFirst 模式开发相关方法
+
+
+ 使用 or 拼接两个 lambda 表达式
+
+
+
+
+
+ 使用 or 拼接两个 lambda 表达式
+
+
+
+ true 时生效
+
+
+
+
+
+ 将 lambda 表达式取反
+
+
+
+ true 时生效
+
+
+
+
+ 生成类似Mongodb的ObjectId有序、不重复Guid
+
+
+
+
+
+ 插入数据
+
+
+
+
+
+
+ 插入数据,传入实体
+
+
+
+
+
+
+
+ 插入数据,传入实体数组
+
+
+
+
+
+
+
+ 插入数据,传入实体集合
+
+
+
+
+
+
+
+ 插入数据,传入实体集合
+
+
+
+
+
+
+
+ 修改数据
+
+
+
+
+
+
+ 修改数据,传入动态对象如:主键值 | new[]{主键值1,主键值2} | TEntity1 | new[]{TEntity1,TEntity2} | new{id=1}
+
+
+ 主键值、主键值集合、实体、实体集合、匿名对象、匿名对象集合
+
+
+
+
+ 查询数据
+
+
+
+
+
+
+ 查询数据,传入动态对象如:主键值 | new[]{主键值1,主键值2} | TEntity1 | new[]{TEntity1,TEntity2} | new{id=1}
+
+
+ 主键值、主键值集合、实体、实体集合、匿名对象、匿名对象集合
+
+
+
+
+ 删除数据
+
+
+
+
+
+
+ 删除数据,传入动态对象如:主键值 | new[]{主键值1,主键值2} | TEntity1 | new[]{TEntity1,TEntity2} | new{id=1}
+
+
+ 主键值、主键值集合、实体、实体集合、匿名对象、匿名对象集合
+
+
+
+
+ 开启事务(不支持异步),60秒未执行完成(可能)被其他线程事务自动提交
+
+ 事务体 () => {}
+
+
+
+ 开启事务(不支持异步)
+
+ 超时,未执行完成(可能)被其他线程事务自动提交
+ 事务体 () => {}
+
+
+
+ 开启事务(不支持异步)
+
+
+ 事务体 () => {}
+ 超时,未执行完成(可能)被其他线程事务自动提交
+
+
+
+ 数据库访问对象
+
+
+
+
+ 所有拦截方法都在这里
+
+
+
+
+ CodeFirst 模式开发相关方法
+
+
DbFirst 模式开发相关方法
diff --git a/Providers/FreeSql.Provider.Sqlite/AdonetPortable.cs b/Providers/FreeSql.Provider.Sqlite/AdonetPortable.cs
deleted file mode 100644
index 6d8dcbf4..00000000
--- a/Providers/FreeSql.Provider.Sqlite/AdonetPortable.cs
+++ /dev/null
@@ -1,61 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Data.Common;
-using System.Reflection;
-using System.Text;
-
-namespace FreeSql.Sqlite
-{
- internal class AdonetPortable
- {
-
-#if ns20
- static bool _IsMicrosoft_Data_Sqlite;
- static object _IsMicrosoft_Data_SqliteLock = new object();
-
- static T PortableAction(Func systemCreate, Func microsoftCreate)
- {
- if (_IsMicrosoft_Data_Sqlite == false)
- {
- try
- {
- return systemCreate();
- }
- catch
- {
- lock (_IsMicrosoft_Data_SqliteLock)
- {
- _IsMicrosoft_Data_Sqlite = true;
- }
- }
- }
- return microsoftCreate();
- }
-
- public static DbConnection GetSqliteConnection(string connectionString) => PortableAction(
- () => new System.Data.SQLite.SQLiteConnection(connectionString),
- () => new Microsoft.Data.Sqlite.SqliteConnection(connectionString));
-
- public static DbCommand GetSqliteCommand() => PortableAction(
- () => new System.Data.SQLite.SQLiteCommand(),
- () => new Microsoft.Data.Sqlite.SqliteCommand());
-
- public static DbParameter GetSqliteParameter() => PortableAction(
- () => new System.Data.SQLite.SQLiteParameter(),
- () => new Microsoft.Data.Sqlite.SqliteParameter());
-
- public static bool IsSqliteException(Exception exception) => PortableAction(
- () => exception is System.Data.SQLite.SQLiteException,
- () => exception is Microsoft.Data.Sqlite.SqliteException);
-#else
-
- public static DbConnection GetSqliteConnection(string connectionString) => new System.Data.SQLite.SQLiteConnection(connectionString);
-
- public static DbCommand GetSqliteCommand() => new System.Data.SQLite.SQLiteCommand();
-
- public static DbParameter GetSqliteParameter() => new System.Data.SQLite.SQLiteParameter();
-
- public static bool IsSqliteException(Exception exception) => exception is System.Data.SQLite.SQLiteException;
-#endif
- }
-}
diff --git a/Providers/FreeSql.Provider.Sqlite/FreeSql.Provider.Sqlite.csproj b/Providers/FreeSql.Provider.Sqlite/FreeSql.Provider.Sqlite.csproj
index fb26a112..48bf9f84 100644
--- a/Providers/FreeSql.Provider.Sqlite/FreeSql.Provider.Sqlite.csproj
+++ b/Providers/FreeSql.Provider.Sqlite/FreeSql.Provider.Sqlite.csproj
@@ -21,13 +21,10 @@
-
-
+
+
-
-
-
diff --git a/Providers/FreeSql.Provider.Sqlite/SqliteAdo/SqliteAdo.cs b/Providers/FreeSql.Provider.Sqlite/SqliteAdo/SqliteAdo.cs
index 4e473739..5745a3e8 100644
--- a/Providers/FreeSql.Provider.Sqlite/SqliteAdo/SqliteAdo.cs
+++ b/Providers/FreeSql.Provider.Sqlite/SqliteAdo/SqliteAdo.cs
@@ -4,6 +4,7 @@ using SafeObjectPool;
using System;
using System.Collections;
using System.Data.Common;
+using System.Data.SQLite;
using System.Text;
using System.Threading;
@@ -18,6 +19,10 @@ namespace FreeSql.Sqlite
if (connectionFactory != null)
{
MasterPool = new FreeSql.Internal.CommonProvider.DbConnectionPool(DataType.Sqlite, connectionFactory);
+ using (var conn = MasterPool.Get())
+ {
+ _CreateCommandConnection = conn.Value;
+ }
return;
}
if (!string.IsNullOrEmpty(masterConnectionString))
@@ -57,9 +62,11 @@ namespace FreeSql.Sqlite
return string.Concat("'", param.ToString().Replace("'", "''"), "'");
}
+ DbConnection _CreateCommandConnection;
protected override DbCommand CreateCommand()
{
- return AdonetPortable.GetSqliteCommand();
+ if (_CreateCommandConnection != null) return _CreateCommandConnection.CreateCommand();
+ return new SQLiteCommand();
}
protected override void ReturnConnection(IObjectPool pool, Object conn, Exception ex)
diff --git a/Providers/FreeSql.Provider.Sqlite/SqliteAdo/SqliteConnectionPool.cs b/Providers/FreeSql.Provider.Sqlite/SqliteAdo/SqliteConnectionPool.cs
index 526dbabd..5257b7e0 100644
--- a/Providers/FreeSql.Provider.Sqlite/SqliteAdo/SqliteConnectionPool.cs
+++ b/Providers/FreeSql.Provider.Sqlite/SqliteAdo/SqliteConnectionPool.cs
@@ -4,6 +4,7 @@ using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
+using System.Data.SQLite;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
@@ -34,7 +35,7 @@ namespace FreeSql.Sqlite
public void Return(Object obj, Exception exception, bool isRecreate = false)
{
- if (exception != null && AdonetPortable.IsSqliteException(exception))
+ if (exception != null && exception is SQLiteException)
{
try { if (obj.Value.Ping() == false) obj.Value.OpenAndAttach(policy.Attaches); } catch { base.SetUnavailable(exception); }
}
@@ -121,7 +122,7 @@ namespace FreeSql.Sqlite
public DbConnection OnCreate()
{
- var conn = AdonetPortable.GetSqliteConnection(_connectionString);
+ var conn = new SQLiteConnection(_connectionString);
return conn;
}
diff --git a/Providers/FreeSql.Provider.Sqlite/SqliteProvider.cs b/Providers/FreeSql.Provider.Sqlite/SqliteProvider.cs
index 138056e9..972137b6 100644
--- a/Providers/FreeSql.Provider.Sqlite/SqliteProvider.cs
+++ b/Providers/FreeSql.Provider.Sqlite/SqliteProvider.cs
@@ -38,6 +38,7 @@ namespace FreeSql.Sqlite
this.Aop = new AopProvider();
this.CodeFirst = new SqliteCodeFirst(this, this.InternalCommonUtils, this.InternalCommonExpression);
+ if (connectionFactory != null) this.CodeFirst.IsNoneCommandParameter = true;
}
internal CommonUtils InternalCommonUtils { get; }
diff --git a/Providers/FreeSql.Provider.Sqlite/SqliteUtils.cs b/Providers/FreeSql.Provider.Sqlite/SqliteUtils.cs
index ef9b986d..41ba2433 100644
--- a/Providers/FreeSql.Provider.Sqlite/SqliteUtils.cs
+++ b/Providers/FreeSql.Provider.Sqlite/SqliteUtils.cs
@@ -4,6 +4,7 @@ using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
+using System.Data.SQLite;
namespace FreeSql.Sqlite
{
@@ -31,7 +32,7 @@ namespace FreeSql.Sqlite
dbtype = DbType.Int64;
break;
}
- var ret = AdonetPortable.GetSqliteParameter();
+ var ret = new SQLiteParameter();
ret.ParameterName = QuoteParamterName(parameterName);
ret.DbType = dbtype;
ret.Value = value;
@@ -56,7 +57,7 @@ namespace FreeSql.Sqlite
dbtype = DbType.Int64;
break;
}
- var ret = AdonetPortable.GetSqliteParameter();
+ var ret = new SQLiteParameter();
ret.ParameterName = $"@{name}";
ret.DbType = dbtype;
ret.Value = value;