mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-06-18 03:53:21 +08:00
- 增加 IDbConnection/IDbTransaction 对象的扩展方法 Select/Insert/Update/Delete 实现 CRUD #267;
This commit is contained in:
parent
8c6ea70663
commit
7c89aafe79
@ -1,37 +0,0 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
|
||||||
|
|
||||||
<PropertyGroup>
|
|
||||||
<TargetFrameworks>netstandard2.0;net45;net40</TargetFrameworks>
|
|
||||||
<Version>1.8.0-preview0815</Version>
|
|
||||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
|
||||||
<Authors>FreeSql;ncc;YeXiangQin</Authors>
|
|
||||||
<Description>FreeSql AdoNet 扩展包,增加 IDbConnection/IDbTransaction 对象的扩展方法 Select/Insert/Update/Delete 实现 CRUD。</Description>
|
|
||||||
<PackageProjectUrl>https://github.com/2881099/FreeSql</PackageProjectUrl>
|
|
||||||
<RepositoryUrl>https://github.com/2881099/FreeSql</RepositoryUrl>
|
|
||||||
<RepositoryType>git</RepositoryType>
|
|
||||||
<PackageLicenseExpression>MIT</PackageLicenseExpression>
|
|
||||||
<PackageTags>FreeSql;ORM</PackageTags>
|
|
||||||
<PackageId>$(AssemblyName)</PackageId>
|
|
||||||
<PackageIcon>logo.png</PackageIcon>
|
|
||||||
<Title>$(AssemblyName)</Title>
|
|
||||||
<IsPackable>true</IsPackable>
|
|
||||||
<GenerateAssemblyInfo>true</GenerateAssemblyInfo>
|
|
||||||
<SignAssembly>true</SignAssembly>
|
|
||||||
<AssemblyOriginatorKeyFile>key.snk</AssemblyOriginatorKeyFile>
|
|
||||||
<DelaySign>false</DelaySign>
|
|
||||||
</PropertyGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<None Include="../../logo.png" Pack="true" PackagePath="\" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|netstandard2.0|AnyCPU'">
|
|
||||||
<DocumentationFile>FreeSql.Extensions.AdoNet.xml</DocumentationFile>
|
|
||||||
<WarningLevel>3</WarningLevel>
|
|
||||||
</PropertyGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<ProjectReference Include="..\..\FreeSql\FreeSql.csproj" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
|
@ -1,217 +0,0 @@
|
|||||||
<?xml version="1.0"?>
|
|
||||||
<doc>
|
|
||||||
<assembly>
|
|
||||||
<name>FreeSql.Extensions.AdoNet</name>
|
|
||||||
</assembly>
|
|
||||||
<members>
|
|
||||||
<member name="M:FreeSqlAdoNetExtensions.GetIFreeSql(System.Data.IDbConnection)">
|
|
||||||
<summary>
|
|
||||||
获取 IDbConnection 对应的 IFreeSql 实例
|
|
||||||
</summary>
|
|
||||||
<param name="that"></param>
|
|
||||||
<returns></returns>
|
|
||||||
</member>
|
|
||||||
<member name="M:FreeSqlAdoNetExtensions.Insert``1(System.Data.IDbConnection)">
|
|
||||||
<summary>
|
|
||||||
插入数据
|
|
||||||
</summary>
|
|
||||||
<typeparam name="T1"></typeparam>
|
|
||||||
<returns></returns>
|
|
||||||
</member>
|
|
||||||
<member name="M:FreeSqlAdoNetExtensions.Insert``1(System.Data.IDbConnection,``0)">
|
|
||||||
<summary>
|
|
||||||
插入数据,传入实体
|
|
||||||
</summary>
|
|
||||||
<typeparam name="T1"></typeparam>
|
|
||||||
<param name="source"></param>
|
|
||||||
<returns></returns>
|
|
||||||
</member>
|
|
||||||
<member name="M:FreeSqlAdoNetExtensions.Insert``1(System.Data.IDbConnection,``0[])">
|
|
||||||
<summary>
|
|
||||||
插入数据,传入实体数组
|
|
||||||
</summary>
|
|
||||||
<typeparam name="T1"></typeparam>
|
|
||||||
<param name="source"></param>
|
|
||||||
<returns></returns>
|
|
||||||
</member>
|
|
||||||
<member name="M:FreeSqlAdoNetExtensions.Insert``1(System.Data.IDbConnection,System.Collections.Generic.List{``0})">
|
|
||||||
<summary>
|
|
||||||
插入数据,传入实体集合
|
|
||||||
</summary>
|
|
||||||
<typeparam name="T1"></typeparam>
|
|
||||||
<param name="source"></param>
|
|
||||||
<returns></returns>
|
|
||||||
</member>
|
|
||||||
<member name="M:FreeSqlAdoNetExtensions.Insert``1(System.Data.IDbConnection,System.Collections.Generic.IEnumerable{``0})">
|
|
||||||
<summary>
|
|
||||||
插入数据,传入实体集合
|
|
||||||
</summary>
|
|
||||||
<typeparam name="T1"></typeparam>
|
|
||||||
<param name="source"></param>
|
|
||||||
<returns></returns>
|
|
||||||
</member>
|
|
||||||
<member name="M:FreeSqlAdoNetExtensions.InsertOrUpdate``1(System.Data.IDbConnection)">
|
|
||||||
<summary>
|
|
||||||
插入或更新数据,此功能依赖数据库特性(低版本可能不支持),参考如下:<para></para>
|
|
||||||
MySql 5.6+: on duplicate key update<para></para>
|
|
||||||
PostgreSQL 9.4+: on conflict do update<para></para>
|
|
||||||
SqlServer 2008+: merge into<para></para>
|
|
||||||
Oracle 11+: merge into<para></para>
|
|
||||||
Sqlite: replace into<para></para>
|
|
||||||
达梦: merge into<para></para>
|
|
||||||
人大金仓:on conflict do update<para></para>
|
|
||||||
神通:merge into<para></para>
|
|
||||||
MsAccess:不支持<para></para>
|
|
||||||
注意区别:FreeSql.Repository 仓储也有 InsertOrUpdate 方法(不依赖数据库特性)
|
|
||||||
</summary>
|
|
||||||
<typeparam name="T1"></typeparam>
|
|
||||||
<returns></returns>
|
|
||||||
</member>
|
|
||||||
<member name="M:FreeSqlAdoNetExtensions.Update``1(System.Data.IDbConnection)">
|
|
||||||
<summary>
|
|
||||||
修改数据
|
|
||||||
</summary>
|
|
||||||
<typeparam name="T1"></typeparam>
|
|
||||||
<returns></returns>
|
|
||||||
</member>
|
|
||||||
<member name="M:FreeSqlAdoNetExtensions.Update``1(System.Data.IDbConnection,System.Object)">
|
|
||||||
<summary>
|
|
||||||
修改数据,传入动态条件,如:主键值 | new[]{主键值1,主键值2} | TEntity1 | new[]{TEntity1,TEntity2} | new{id=1}
|
|
||||||
</summary>
|
|
||||||
<typeparam name="T1"></typeparam>
|
|
||||||
<param name="dywhere">主键值、主键值集合、实体、实体集合、匿名对象、匿名对象集合</param>
|
|
||||||
<returns></returns>
|
|
||||||
</member>
|
|
||||||
<member name="M:FreeSqlAdoNetExtensions.Select``1(System.Data.IDbConnection)">
|
|
||||||
<summary>
|
|
||||||
查询数据
|
|
||||||
</summary>
|
|
||||||
<typeparam name="T1"></typeparam>
|
|
||||||
<returns></returns>
|
|
||||||
</member>
|
|
||||||
<member name="M:FreeSqlAdoNetExtensions.Select``1(System.Data.IDbConnection,System.Object)">
|
|
||||||
<summary>
|
|
||||||
查询数据,传入动态条件,如:主键值 | new[]{主键值1,主键值2} | TEntity1 | new[]{TEntity1,TEntity2} | new{id=1}
|
|
||||||
</summary>
|
|
||||||
<typeparam name="T1"></typeparam>
|
|
||||||
<param name="dywhere">主键值、主键值集合、实体、实体集合、匿名对象、匿名对象集合</param>
|
|
||||||
<returns></returns>
|
|
||||||
</member>
|
|
||||||
<member name="M:FreeSqlAdoNetExtensions.Delete``1(System.Data.IDbConnection)">
|
|
||||||
<summary>
|
|
||||||
删除数据
|
|
||||||
</summary>
|
|
||||||
<typeparam name="T1"></typeparam>
|
|
||||||
<returns></returns>
|
|
||||||
</member>
|
|
||||||
<member name="M:FreeSqlAdoNetExtensions.Delete``1(System.Data.IDbConnection,System.Object)">
|
|
||||||
<summary>
|
|
||||||
删除数据,传入动态条件,如:主键值 | new[]{主键值1,主键值2} | TEntity1 | new[]{TEntity1,TEntity2} | new{id=1}
|
|
||||||
</summary>
|
|
||||||
<typeparam name="T1"></typeparam>
|
|
||||||
<param name="dywhere">主键值、主键值集合、实体、实体集合、匿名对象、匿名对象集合</param>
|
|
||||||
<returns></returns>
|
|
||||||
</member>
|
|
||||||
<member name="M:FreeSqlAdoNetExtensions.Insert``1(System.Data.IDbTransaction)">
|
|
||||||
<summary>
|
|
||||||
插入数据
|
|
||||||
</summary>
|
|
||||||
<typeparam name="T1"></typeparam>
|
|
||||||
<returns></returns>
|
|
||||||
</member>
|
|
||||||
<member name="M:FreeSqlAdoNetExtensions.Insert``1(System.Data.IDbTransaction,``0)">
|
|
||||||
<summary>
|
|
||||||
插入数据,传入实体
|
|
||||||
</summary>
|
|
||||||
<typeparam name="T1"></typeparam>
|
|
||||||
<param name="source"></param>
|
|
||||||
<returns></returns>
|
|
||||||
</member>
|
|
||||||
<member name="M:FreeSqlAdoNetExtensions.Insert``1(System.Data.IDbTransaction,``0[])">
|
|
||||||
<summary>
|
|
||||||
插入数据,传入实体数组
|
|
||||||
</summary>
|
|
||||||
<typeparam name="T1"></typeparam>
|
|
||||||
<param name="source"></param>
|
|
||||||
<returns></returns>
|
|
||||||
</member>
|
|
||||||
<member name="M:FreeSqlAdoNetExtensions.Insert``1(System.Data.IDbTransaction,System.Collections.Generic.List{``0})">
|
|
||||||
<summary>
|
|
||||||
插入数据,传入实体集合
|
|
||||||
</summary>
|
|
||||||
<typeparam name="T1"></typeparam>
|
|
||||||
<param name="source"></param>
|
|
||||||
<returns></returns>
|
|
||||||
</member>
|
|
||||||
<member name="M:FreeSqlAdoNetExtensions.Insert``1(System.Data.IDbTransaction,System.Collections.Generic.IEnumerable{``0})">
|
|
||||||
<summary>
|
|
||||||
插入数据,传入实体集合
|
|
||||||
</summary>
|
|
||||||
<typeparam name="T1"></typeparam>
|
|
||||||
<param name="source"></param>
|
|
||||||
<returns></returns>
|
|
||||||
</member>
|
|
||||||
<member name="M:FreeSqlAdoNetExtensions.InsertOrUpdate``1(System.Data.IDbTransaction)">
|
|
||||||
<summary>
|
|
||||||
插入或更新数据,此功能依赖数据库特性(低版本可能不支持),参考如下:<para></para>
|
|
||||||
MySql 5.6+: on duplicate key update<para></para>
|
|
||||||
PostgreSQL 9.4+: on conflict do update<para></para>
|
|
||||||
SqlServer 2008+: merge into<para></para>
|
|
||||||
Oracle 11+: merge into<para></para>
|
|
||||||
Sqlite: replace into<para></para>
|
|
||||||
达梦: merge into<para></para>
|
|
||||||
人大金仓:on conflict do update<para></para>
|
|
||||||
神通:merge into<para></para>
|
|
||||||
MsAccess:不支持<para></para>
|
|
||||||
注意区别:FreeSql.Repository 仓储也有 InsertOrUpdate 方法(不依赖数据库特性)
|
|
||||||
</summary>
|
|
||||||
<typeparam name="T1"></typeparam>
|
|
||||||
<returns></returns>
|
|
||||||
</member>
|
|
||||||
<member name="M:FreeSqlAdoNetExtensions.Update``1(System.Data.IDbTransaction)">
|
|
||||||
<summary>
|
|
||||||
修改数据
|
|
||||||
</summary>
|
|
||||||
<typeparam name="T1"></typeparam>
|
|
||||||
<returns></returns>
|
|
||||||
</member>
|
|
||||||
<member name="M:FreeSqlAdoNetExtensions.Update``1(System.Data.IDbTransaction,System.Object)">
|
|
||||||
<summary>
|
|
||||||
修改数据,传入动态条件,如:主键值 | new[]{主键值1,主键值2} | TEntity1 | new[]{TEntity1,TEntity2} | new{id=1}
|
|
||||||
</summary>
|
|
||||||
<typeparam name="T1"></typeparam>
|
|
||||||
<param name="dywhere">主键值、主键值集合、实体、实体集合、匿名对象、匿名对象集合</param>
|
|
||||||
<returns></returns>
|
|
||||||
</member>
|
|
||||||
<member name="M:FreeSqlAdoNetExtensions.Select``1(System.Data.IDbTransaction)">
|
|
||||||
<summary>
|
|
||||||
查询数据
|
|
||||||
</summary>
|
|
||||||
<typeparam name="T1"></typeparam>
|
|
||||||
<returns></returns>
|
|
||||||
</member>
|
|
||||||
<member name="M:FreeSqlAdoNetExtensions.Select``1(System.Data.IDbTransaction,System.Object)">
|
|
||||||
<summary>
|
|
||||||
查询数据,传入动态条件,如:主键值 | new[]{主键值1,主键值2} | TEntity1 | new[]{TEntity1,TEntity2} | new{id=1}
|
|
||||||
</summary>
|
|
||||||
<typeparam name="T1"></typeparam>
|
|
||||||
<param name="dywhere">主键值、主键值集合、实体、实体集合、匿名对象、匿名对象集合</param>
|
|
||||||
<returns></returns>
|
|
||||||
</member>
|
|
||||||
<member name="M:FreeSqlAdoNetExtensions.Delete``1(System.Data.IDbTransaction)">
|
|
||||||
<summary>
|
|
||||||
删除数据
|
|
||||||
</summary>
|
|
||||||
<typeparam name="T1"></typeparam>
|
|
||||||
<returns></returns>
|
|
||||||
</member>
|
|
||||||
<member name="M:FreeSqlAdoNetExtensions.Delete``1(System.Data.IDbTransaction,System.Object)">
|
|
||||||
<summary>
|
|
||||||
删除数据,传入动态条件,如:主键值 | new[]{主键值1,主键值2} | TEntity1 | new[]{TEntity1,TEntity2} | new{id=1}
|
|
||||||
</summary>
|
|
||||||
<typeparam name="T1"></typeparam>
|
|
||||||
<param name="dywhere">主键值、主键值集合、实体、实体集合、匿名对象、匿名对象集合</param>
|
|
||||||
<returns></returns>
|
|
||||||
</member>
|
|
||||||
</members>
|
|
||||||
</doc>
|
|
@ -1,265 +0,0 @@
|
|||||||
using FreeSql;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Data;
|
|
||||||
using System.Data.Common;
|
|
||||||
|
|
||||||
public static class FreeSqlAdoNetExtensions
|
|
||||||
{
|
|
||||||
static Dictionary<Type, IFreeSql> _dicCurd = new Dictionary<Type, IFreeSql>();
|
|
||||||
static object _dicCurdLock = new object();
|
|
||||||
static IFreeSql GetCrud(IDbConnection dbconn)
|
|
||||||
{
|
|
||||||
if (dbconn == null) throw new ArgumentNullException($"{nameof(dbconn)} 不能为 null"); ;
|
|
||||||
Type dbconType = dbconn.GetType();
|
|
||||||
var connType = dbconType.UnderlyingSystemType;
|
|
||||||
if (_dicCurd.TryGetValue(connType, out var fsql)) return fsql;
|
|
||||||
|
|
||||||
Type providerType = null;
|
|
||||||
switch (connType.Name)
|
|
||||||
{
|
|
||||||
case "MySqlConnection":
|
|
||||||
providerType = Type.GetType("FreeSql.MySql.MySqlProvider`1,FreeSql.Provider.MySql")?.MakeGenericType(connType);
|
|
||||||
if (providerType == null) providerType = Type.GetType("FreeSql.MySql.MySqlProvider`1,FreeSql.Provider.MySqlConnector")?.MakeGenericType(connType);
|
|
||||||
if (providerType == null) throw new Exception("缺少 FreeSql 数据库实现包:FreeSql.Provider.MySql.dll,可前往 nuget 下载");
|
|
||||||
break;
|
|
||||||
case "SqlConnection":
|
|
||||||
providerType = Type.GetType("FreeSql.SqlServer.SqlServerProvider`1,FreeSql.Provider.SqlServer")?.MakeGenericType(connType);
|
|
||||||
if (providerType == null) throw new Exception("缺少 FreeSql 数据库实现包:FreeSql.Provider.SqlServer.dll,可前往 nuget 下载");
|
|
||||||
break;
|
|
||||||
case "NpgsqlConnection":
|
|
||||||
providerType = Type.GetType("FreeSql.PostgreSQL.PostgreSQLProvider`1,FreeSql.Provider.PostgreSQL")?.MakeGenericType(connType);
|
|
||||||
if (providerType == null) throw new Exception("缺少 FreeSql 数据库实现包:FreeSql.Provider.PostgreSQL.dll,可前往 nuget 下载");
|
|
||||||
break;
|
|
||||||
case "OracleConnection":
|
|
||||||
providerType = Type.GetType("FreeSql.Oracle.OracleProvider`1,FreeSql.Provider.Oracle")?.MakeGenericType(connType);
|
|
||||||
if (providerType == null) throw new Exception("缺少 FreeSql 数据库实现包:FreeSql.Provider.Oracle.dll,可前往 nuget 下载");
|
|
||||||
break;
|
|
||||||
case "SQLiteConnection":
|
|
||||||
providerType = Type.GetType("FreeSql.Sqlite.SqliteProvider`1,FreeSql.Provider.Sqlite")?.MakeGenericType(connType);
|
|
||||||
if (providerType == null) throw new Exception("缺少 FreeSql 数据库实现包:FreeSql.Provider.Sqlite.dll,可前往 nuget 下载");
|
|
||||||
break;
|
|
||||||
case "DmConnection":
|
|
||||||
providerType = Type.GetType("FreeSql.Dameng.DamengProvider`1,FreeSql.Provider.Dameng")?.MakeGenericType(connType);
|
|
||||||
if (providerType == null) throw new Exception("缺少 FreeSql 数据库实现包:FreeSql.Provider.Dameng.dll,可前往 nuget 下载");
|
|
||||||
break;
|
|
||||||
case "OscarConnection":
|
|
||||||
providerType = Type.GetType("FreeSql.ShenTong.ShenTongProvider`1,FreeSql.Provider.ShenTong")?.MakeGenericType(connType);
|
|
||||||
if (providerType == null) throw new Exception("缺少 FreeSql 数据库实现包:FreeSql.Provider.ShenTong.dll,可前往 nuget 下载");
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw new Exception("未实现");
|
|
||||||
}
|
|
||||||
lock (_dicCurdLock)
|
|
||||||
{
|
|
||||||
if (_dicCurd.TryGetValue(connType, out fsql)) return fsql;
|
|
||||||
lock (_dicCurdLock)
|
|
||||||
_dicCurd.Add(connType, fsql = Activator.CreateInstance(providerType, new object[] { null, null, null }) as IFreeSql);
|
|
||||||
}
|
|
||||||
return fsql;
|
|
||||||
}
|
|
||||||
static IFreeSql GetCrud(IDbTransaction dbtran)
|
|
||||||
{
|
|
||||||
if (dbtran == null) throw new ArgumentNullException($"{nameof(dbtran)} 不能为 null");
|
|
||||||
return GetCrud(dbtran.Connection);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 获取 IDbConnection 对应的 IFreeSql 实例
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="that"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static IFreeSql GetIFreeSql(this IDbConnection that) => GetCrud(that);
|
|
||||||
|
|
||||||
#region IDbConnection
|
|
||||||
/// <summary>
|
|
||||||
/// 插入数据
|
|
||||||
/// </summary>
|
|
||||||
/// <typeparam name="T1"></typeparam>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static IInsert<T1> Insert<T1>(this IDbConnection that) where T1 : class => GetCrud(that).Insert<T1>().WithConnection(that as DbConnection);
|
|
||||||
/// <summary>
|
|
||||||
/// 插入数据,传入实体
|
|
||||||
/// </summary>
|
|
||||||
/// <typeparam name="T1"></typeparam>
|
|
||||||
/// <param name="source"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static IInsert<T1> Insert<T1>(this IDbConnection that, T1 source) where T1 : class => GetCrud(that).Insert<T1>(source).WithConnection(that as DbConnection);
|
|
||||||
/// <summary>
|
|
||||||
/// 插入数据,传入实体数组
|
|
||||||
/// </summary>
|
|
||||||
/// <typeparam name="T1"></typeparam>
|
|
||||||
/// <param name="source"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static IInsert<T1> Insert<T1>(this IDbConnection that, T1[] source) where T1 : class => GetCrud(that).Insert<T1>(source).WithConnection(that as DbConnection);
|
|
||||||
/// <summary>
|
|
||||||
/// 插入数据,传入实体集合
|
|
||||||
/// </summary>
|
|
||||||
/// <typeparam name="T1"></typeparam>
|
|
||||||
/// <param name="source"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static IInsert<T1> Insert<T1>(this IDbConnection that, List<T1> source) where T1 : class => GetCrud(that).Insert<T1>(source).WithConnection(that as DbConnection);
|
|
||||||
/// <summary>
|
|
||||||
/// 插入数据,传入实体集合
|
|
||||||
/// </summary>
|
|
||||||
/// <typeparam name="T1"></typeparam>
|
|
||||||
/// <param name="source"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static IInsert<T1> Insert<T1>(this IDbConnection that, IEnumerable<T1> source) where T1 : class => GetCrud(that).Insert<T1>(source).WithConnection(that as DbConnection);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 插入或更新数据,此功能依赖数据库特性(低版本可能不支持),参考如下:<para></para>
|
|
||||||
/// MySql 5.6+: on duplicate key update<para></para>
|
|
||||||
/// PostgreSQL 9.4+: on conflict do update<para></para>
|
|
||||||
/// SqlServer 2008+: merge into<para></para>
|
|
||||||
/// Oracle 11+: merge into<para></para>
|
|
||||||
/// Sqlite: replace into<para></para>
|
|
||||||
/// 达梦: merge into<para></para>
|
|
||||||
/// 人大金仓:on conflict do update<para></para>
|
|
||||||
/// 神通:merge into<para></para>
|
|
||||||
/// MsAccess:不支持<para></para>
|
|
||||||
/// 注意区别:FreeSql.Repository 仓储也有 InsertOrUpdate 方法(不依赖数据库特性)
|
|
||||||
/// </summary>
|
|
||||||
/// <typeparam name="T1"></typeparam>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static IInsertOrUpdate<T1> InsertOrUpdate<T1>(this IDbConnection that) where T1 : class => GetCrud(that).InsertOrUpdate<T1>().WithConnection(that as DbConnection);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 修改数据
|
|
||||||
/// </summary>
|
|
||||||
/// <typeparam name="T1"></typeparam>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static IUpdate<T1> Update<T1>(this IDbConnection that) where T1 : class => GetCrud(that).Update<T1>().WithConnection(that as DbConnection);
|
|
||||||
/// <summary>
|
|
||||||
/// 修改数据,传入动态条件,如:主键值 | new[]{主键值1,主键值2} | TEntity1 | new[]{TEntity1,TEntity2} | new{id=1}
|
|
||||||
/// </summary>
|
|
||||||
/// <typeparam name="T1"></typeparam>
|
|
||||||
/// <param name="dywhere">主键值、主键值集合、实体、实体集合、匿名对象、匿名对象集合</param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static IUpdate<T1> Update<T1>(this IDbConnection that, object dywhere) where T1 : class => GetCrud(that).Update<T1>(dywhere).WithConnection(that as DbConnection);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 查询数据
|
|
||||||
/// </summary>
|
|
||||||
/// <typeparam name="T1"></typeparam>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static ISelect<T1> Select<T1>(this IDbConnection that) where T1 : class => GetCrud(that).Select<T1>().WithConnection(that as DbConnection);
|
|
||||||
/// <summary>
|
|
||||||
/// 查询数据,传入动态条件,如:主键值 | new[]{主键值1,主键值2} | TEntity1 | new[]{TEntity1,TEntity2} | new{id=1}
|
|
||||||
/// </summary>
|
|
||||||
/// <typeparam name="T1"></typeparam>
|
|
||||||
/// <param name="dywhere">主键值、主键值集合、实体、实体集合、匿名对象、匿名对象集合</param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static ISelect<T1> Select<T1>(this IDbConnection that, object dywhere) where T1 : class => GetCrud(that).Select<T1>(dywhere).WithConnection(that as DbConnection);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 删除数据
|
|
||||||
/// </summary>
|
|
||||||
/// <typeparam name="T1"></typeparam>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static IDelete<T1> Delete<T1>(this IDbConnection that) where T1 : class => GetCrud(that).Delete<T1>().WithConnection(that as DbConnection);
|
|
||||||
/// <summary>
|
|
||||||
/// 删除数据,传入动态条件,如:主键值 | new[]{主键值1,主键值2} | TEntity1 | new[]{TEntity1,TEntity2} | new{id=1}
|
|
||||||
/// </summary>
|
|
||||||
/// <typeparam name="T1"></typeparam>
|
|
||||||
/// <param name="dywhere">主键值、主键值集合、实体、实体集合、匿名对象、匿名对象集合</param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static IDelete<T1> Delete<T1>(this IDbConnection that, object dywhere) where T1 : class => GetCrud(that).Delete<T1>(dywhere).WithConnection(that as DbConnection);
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region IDbTransaction
|
|
||||||
/// <summary>
|
|
||||||
/// 插入数据
|
|
||||||
/// </summary>
|
|
||||||
/// <typeparam name="T1"></typeparam>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static IInsert<T1> Insert<T1>(this IDbTransaction that) where T1 : class => GetCrud(that).Insert<T1>().WithTransaction(that as DbTransaction);
|
|
||||||
/// <summary>
|
|
||||||
/// 插入数据,传入实体
|
|
||||||
/// </summary>
|
|
||||||
/// <typeparam name="T1"></typeparam>
|
|
||||||
/// <param name="source"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static IInsert<T1> Insert<T1>(this IDbTransaction that, T1 source) where T1 : class => GetCrud(that).Insert<T1>(source).WithTransaction(that as DbTransaction);
|
|
||||||
/// <summary>
|
|
||||||
/// 插入数据,传入实体数组
|
|
||||||
/// </summary>
|
|
||||||
/// <typeparam name="T1"></typeparam>
|
|
||||||
/// <param name="source"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static IInsert<T1> Insert<T1>(this IDbTransaction that, T1[] source) where T1 : class => GetCrud(that).Insert<T1>(source).WithTransaction(that as DbTransaction);
|
|
||||||
/// <summary>
|
|
||||||
/// 插入数据,传入实体集合
|
|
||||||
/// </summary>
|
|
||||||
/// <typeparam name="T1"></typeparam>
|
|
||||||
/// <param name="source"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static IInsert<T1> Insert<T1>(this IDbTransaction that, List<T1> source) where T1 : class => GetCrud(that).Insert<T1>(source).WithTransaction(that as DbTransaction);
|
|
||||||
/// <summary>
|
|
||||||
/// 插入数据,传入实体集合
|
|
||||||
/// </summary>
|
|
||||||
/// <typeparam name="T1"></typeparam>
|
|
||||||
/// <param name="source"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static IInsert<T1> Insert<T1>(this IDbTransaction that, IEnumerable<T1> source) where T1 : class => GetCrud(that).Insert<T1>(source).WithTransaction(that as DbTransaction);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 插入或更新数据,此功能依赖数据库特性(低版本可能不支持),参考如下:<para></para>
|
|
||||||
/// MySql 5.6+: on duplicate key update<para></para>
|
|
||||||
/// PostgreSQL 9.4+: on conflict do update<para></para>
|
|
||||||
/// SqlServer 2008+: merge into<para></para>
|
|
||||||
/// Oracle 11+: merge into<para></para>
|
|
||||||
/// Sqlite: replace into<para></para>
|
|
||||||
/// 达梦: merge into<para></para>
|
|
||||||
/// 人大金仓:on conflict do update<para></para>
|
|
||||||
/// 神通:merge into<para></para>
|
|
||||||
/// MsAccess:不支持<para></para>
|
|
||||||
/// 注意区别:FreeSql.Repository 仓储也有 InsertOrUpdate 方法(不依赖数据库特性)
|
|
||||||
/// </summary>
|
|
||||||
/// <typeparam name="T1"></typeparam>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static IInsertOrUpdate<T1> InsertOrUpdate<T1>(this IDbTransaction that) where T1 : class => GetCrud(that).InsertOrUpdate<T1>().WithTransaction(that as DbTransaction);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 修改数据
|
|
||||||
/// </summary>
|
|
||||||
/// <typeparam name="T1"></typeparam>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static IUpdate<T1> Update<T1>(this IDbTransaction that) where T1 : class => GetCrud(that).Update<T1>().WithTransaction(that as DbTransaction);
|
|
||||||
/// <summary>
|
|
||||||
/// 修改数据,传入动态条件,如:主键值 | new[]{主键值1,主键值2} | TEntity1 | new[]{TEntity1,TEntity2} | new{id=1}
|
|
||||||
/// </summary>
|
|
||||||
/// <typeparam name="T1"></typeparam>
|
|
||||||
/// <param name="dywhere">主键值、主键值集合、实体、实体集合、匿名对象、匿名对象集合</param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static IUpdate<T1> Update<T1>(this IDbTransaction that, object dywhere) where T1 : class => GetCrud(that).Update<T1>(dywhere).WithTransaction(that as DbTransaction);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 查询数据
|
|
||||||
/// </summary>
|
|
||||||
/// <typeparam name="T1"></typeparam>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static ISelect<T1> Select<T1>(this IDbTransaction that) where T1 : class => GetCrud(that).Select<T1>().WithTransaction(that as DbTransaction);
|
|
||||||
/// <summary>
|
|
||||||
/// 查询数据,传入动态条件,如:主键值 | new[]{主键值1,主键值2} | TEntity1 | new[]{TEntity1,TEntity2} | new{id=1}
|
|
||||||
/// </summary>
|
|
||||||
/// <typeparam name="T1"></typeparam>
|
|
||||||
/// <param name="dywhere">主键值、主键值集合、实体、实体集合、匿名对象、匿名对象集合</param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static ISelect<T1> Select<T1>(this IDbTransaction that, object dywhere) where T1 : class => GetCrud(that).Select<T1>(dywhere).WithTransaction(that as DbTransaction);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 删除数据
|
|
||||||
/// </summary>
|
|
||||||
/// <typeparam name="T1"></typeparam>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static IDelete<T1> Delete<T1>(this IDbTransaction that) where T1 : class => GetCrud(that).Delete<T1>().WithTransaction(that as DbTransaction);
|
|
||||||
/// <summary>
|
|
||||||
/// 删除数据,传入动态条件,如:主键值 | new[]{主键值1,主键值2} | TEntity1 | new[]{TEntity1,TEntity2} | new{id=1}
|
|
||||||
/// </summary>
|
|
||||||
/// <typeparam name="T1"></typeparam>
|
|
||||||
/// <param name="dywhere">主键值、主键值集合、实体、实体集合、匿名对象、匿名对象集合</param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static IDelete<T1> Delete<T1>(this IDbTransaction that, object dywhere) where T1 : class => GetCrud(that).Delete<T1>(dywhere).WithTransaction(that as DbTransaction);
|
|
||||||
#endregion
|
|
||||||
}
|
|
Binary file not shown.
@ -1,23 +0,0 @@
|
|||||||
FreeSql AdoNet 扩展包,增加 IDbConnection/IDbTransaction 对象的扩展方法 Select/Insert/Update/Delete 实现 CRUD。
|
|
||||||
|
|
||||||
## 如果在 abp-vnext 中使用?
|
|
||||||
|
|
||||||
本方法依赖 Volo.Abp.Dapper,所以也依赖 Volo.Abp.EntityFrameworkCore
|
|
||||||
|
|
||||||
提示:FreeSql 兼容 EFCore 99% 的实体特性
|
|
||||||
|
|
||||||
> dotnet add package FreeSql.Extensions.AdoNet
|
|
||||||
|
|
||||||
```csharp
|
|
||||||
IDapperRepository repo = ...;
|
|
||||||
|
|
||||||
repo.DbConnection.Select<T>().Where(...).ToList();
|
|
||||||
|
|
||||||
repo.DbConnection.Insert(new T {}).ExecuteAffrows();
|
|
||||||
|
|
||||||
repo.DbConnection.Update().SetSource(new T {}).ExecuteAffrows();
|
|
||||||
|
|
||||||
repo.DbConnection.Delete<T>().Where(...).ExecuteAffrows();
|
|
||||||
|
|
||||||
IFreeSql fsql = repo.DbConnection.GetFreeSql(); //获取 IFreeSql 实例
|
|
||||||
```
|
|
@ -1,26 +0,0 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
|
||||||
|
|
||||||
<PropertyGroup>
|
|
||||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
|
||||||
<IsPackable>false</IsPackable>
|
|
||||||
</PropertyGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0-preview-20191216-02" />
|
|
||||||
<PackageReference Include="xunit" Version="2.4.0" />
|
|
||||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<ProjectReference Include="..\..\Extensions\FreeSql.Extensions.AdoNet\FreeSql.Extensions.AdoNet.csproj" />
|
|
||||||
<ProjectReference Include="..\..\FreeSql\FreeSql.csproj" />
|
|
||||||
<ProjectReference Include="..\..\Providers\FreeSql.Provider.Dameng\FreeSql.Provider.Dameng.csproj" />
|
|
||||||
<ProjectReference Include="..\..\Providers\FreeSql.Provider.MySql\FreeSql.Provider.MySql.csproj" />
|
|
||||||
<ProjectReference Include="..\..\Providers\FreeSql.Provider.Oracle\FreeSql.Provider.Oracle.csproj" />
|
|
||||||
<ProjectReference Include="..\..\Providers\FreeSql.Provider.PostgreSQL\FreeSql.Provider.PostgreSQL.csproj" />
|
|
||||||
<ProjectReference Include="..\..\Providers\FreeSql.Provider.ShenTong\FreeSql.Provider.ShenTong.csproj" />
|
|
||||||
<ProjectReference Include="..\..\Providers\FreeSql.Provider.Sqlite\FreeSql.Provider.Sqlite.csproj" />
|
|
||||||
<ProjectReference Include="..\..\Providers\FreeSql.Provider.SqlServer\FreeSql.Provider.SqlServer.csproj" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
|
@ -1,80 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Diagnostics;
|
|
||||||
|
|
||||||
|
|
||||||
public class g {
|
|
||||||
|
|
||||||
static Lazy<IFreeSql> sqlserverLazy = new Lazy<IFreeSql>(() => new FreeSql.FreeSqlBuilder()
|
|
||||||
.UseConnectionString(FreeSql.DataType.SqlServer, "Data Source=.;Integrated Security=True;Initial Catalog=freesqlTest;Pooling=true;Max Pool Size=10")
|
|
||||||
.UseAutoSyncStructure(true)
|
|
||||||
.UseMonitorCommand(
|
|
||||||
cmd => {
|
|
||||||
Trace.WriteLine(cmd.CommandText);
|
|
||||||
}, //监听SQL命令对象,在执行前
|
|
||||||
(cmd, traceLog) => {
|
|
||||||
Console.WriteLine(traceLog);
|
|
||||||
}) //监听SQL命令对象,在执行后
|
|
||||||
.UseLazyLoading(true)
|
|
||||||
.Build());
|
|
||||||
public static IFreeSql sqlserver => sqlserverLazy.Value;
|
|
||||||
|
|
||||||
static Lazy<IFreeSql> mysqlLazy = new Lazy<IFreeSql>(() => new FreeSql.FreeSqlBuilder()
|
|
||||||
.UseConnectionString(FreeSql.DataType.MySql, "Data Source=127.0.0.1;Port=3306;User ID=root;Password=root;Initial Catalog=cccddd;Charset=utf8;SslMode=none;Max pool size=10")
|
|
||||||
.UseAutoSyncStructure(true)
|
|
||||||
.UseMonitorCommand(
|
|
||||||
cmd => {
|
|
||||||
Trace.WriteLine(cmd.CommandText);
|
|
||||||
}, //监听SQL命令对象,在执行前
|
|
||||||
(cmd, traceLog) => {
|
|
||||||
Console.WriteLine(traceLog);
|
|
||||||
}) //监听SQL命令对象,在执行后
|
|
||||||
.UseLazyLoading(true)
|
|
||||||
.Build());
|
|
||||||
public static IFreeSql mysql => mysqlLazy.Value;
|
|
||||||
|
|
||||||
static Lazy<IFreeSql> pgsqlLazy = new Lazy<IFreeSql>(() => new FreeSql.FreeSqlBuilder()
|
|
||||||
.UseConnectionString(FreeSql.DataType.PostgreSQL, "Host=192.168.164.10;Port=5432;Username=postgres;Password=123456;Database=tedb;Pooling=true;Maximum Pool Size=10")
|
|
||||||
.UseAutoSyncStructure(true)
|
|
||||||
.UseNameConvert(FreeSql.Internal.NameConvertType.ToLower)
|
|
||||||
.UseLazyLoading(true)
|
|
||||||
.UseMonitorCommand(
|
|
||||||
cmd => {
|
|
||||||
Trace.WriteLine(cmd.CommandText);
|
|
||||||
}, //监听SQL命令对象,在执行前
|
|
||||||
(cmd, traceLog) => {
|
|
||||||
Console.WriteLine(traceLog);
|
|
||||||
}) //监听SQL命令对象,在执行后
|
|
||||||
.Build());
|
|
||||||
public static IFreeSql pgsql => pgsqlLazy.Value;
|
|
||||||
|
|
||||||
static Lazy<IFreeSql> oracleLazy = new Lazy<IFreeSql>(() => new FreeSql.FreeSqlBuilder()
|
|
||||||
.UseConnectionString(FreeSql.DataType.Oracle, "user id=user1;password=123456;data source=//127.0.0.1:1521/XE;Pooling=true;Max Pool Size=10")
|
|
||||||
.UseAutoSyncStructure(true)
|
|
||||||
.UseLazyLoading(true)
|
|
||||||
.UseNameConvert(FreeSql.Internal.NameConvertType.ToUpper)
|
|
||||||
//.UseNoneCommandParameter(true)
|
|
||||||
|
|
||||||
.UseMonitorCommand(
|
|
||||||
cmd => {
|
|
||||||
Trace.WriteLine(cmd.CommandText);
|
|
||||||
}, //监听SQL命令对象,在执行前
|
|
||||||
(cmd, traceLog) => {
|
|
||||||
Console.WriteLine(traceLog);
|
|
||||||
}) //监听SQL命令对象,在执行后
|
|
||||||
.Build());
|
|
||||||
public static IFreeSql oracle = oracleLazy.Value;
|
|
||||||
|
|
||||||
static Lazy<IFreeSql> sqliteLazy = new Lazy<IFreeSql>(() => new FreeSql.FreeSqlBuilder()
|
|
||||||
.UseConnectionString(FreeSql.DataType.Sqlite, @"Data Source=|DataDirectory|\document.db;Attachs=xxxtb.db;Pooling=true;Max Pool Size=10")
|
|
||||||
.UseAutoSyncStructure(true)
|
|
||||||
.UseLazyLoading(true)
|
|
||||||
.UseMonitorCommand(
|
|
||||||
cmd => {
|
|
||||||
Trace.WriteLine(cmd.CommandText);
|
|
||||||
}, //监听SQL命令对象,在执行前
|
|
||||||
(cmd, traceLog) => {
|
|
||||||
Console.WriteLine(traceLog);
|
|
||||||
}) //监听SQL命令对象,在执行后
|
|
||||||
.Build());
|
|
||||||
public static IFreeSql sqlite = sqliteLazy.Value;
|
|
||||||
}
|
|
@ -3,7 +3,7 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Tests.MySqlConnectionExtensions {
|
namespace FreeSql.Tests.AdoNetExtensions.MySqlConnectionExtensions {
|
||||||
public class Methods {
|
public class Methods {
|
||||||
|
|
||||||
string _connectString = "Data Source=127.0.0.1;Port=3306;User ID=root;Password=root;Initial Catalog=cccddd;Charset=utf8;SslMode=none;Max pool size=5";
|
string _connectString = "Data Source=127.0.0.1;Port=3306;User ID=root;Password=root;Initial Catalog=cccddd;Charset=utf8;SslMode=none;Max pool size=5";
|
@ -3,7 +3,7 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Tests.NpgsqlConnectionExtensions {
|
namespace FreeSql.Tests.AdoNetExtensions.NpgsqlConnectionExtensions {
|
||||||
public class Methods {
|
public class Methods {
|
||||||
|
|
||||||
string _connectString = "Host=192.168.164.10;Port=5432;Username=postgres;Password=123456;Database=tedb;Pooling=true;Maximum Pool Size=5";
|
string _connectString = "Host=192.168.164.10;Port=5432;Username=postgres;Password=123456;Database=tedb;Pooling=true;Maximum Pool Size=5";
|
@ -3,7 +3,7 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Tests.OracleConnectionExtensions {
|
namespace FreeSql.Tests.AdoNetExtensions.OracleConnectionExtensions {
|
||||||
public class Methods {
|
public class Methods {
|
||||||
|
|
||||||
string _connectString = "user id=user1;password=123456;data source=//127.0.0.1:1521/XE;Pooling=true;Max Pool Size=5";
|
string _connectString = "user id=user1;password=123456;data source=//127.0.0.1:1521/XE;Pooling=true;Max Pool Size=5";
|
@ -5,7 +5,7 @@ using System.Data.Common;
|
|||||||
using System.Data.SQLite;
|
using System.Data.SQLite;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Tests.SQLiteConnectionExtensions {
|
namespace FreeSql.Tests.AdoNetExtensions.SQLiteConnectionExtensions {
|
||||||
public class Methods {
|
public class Methods {
|
||||||
|
|
||||||
string _connectString = "Data Source=|DataDirectory|/document.db;Attachs=xxxtb.db;Pooling=true;Max Pool Size=5";
|
string _connectString = "Data Source=|DataDirectory|/document.db;Attachs=xxxtb.db;Pooling=true;Max Pool Size=5";
|
@ -3,7 +3,7 @@ using System.Collections.Generic;
|
|||||||
using Microsoft.Data.SqlClient;
|
using Microsoft.Data.SqlClient;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Tests.SqlConnectionExtensions {
|
namespace FreeSql.Tests.AdoNetExtensions.SqlConnectionExtensions {
|
||||||
public class Methods {
|
public class Methods {
|
||||||
|
|
||||||
string _connectString = "Data Source=.;Integrated Security=True;Initial Catalog=freesqlTest;Pooling=true;Max Pool Size=5";
|
string _connectString = "Data Source=.;Integrated Security=True;Initial Catalog=freesqlTest;Pooling=true;Max Pool Size=5";
|
29
FreeSql.sln
29
FreeSql.sln
@ -86,10 +86,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FreeSql.Tests.Provider.Post
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FreeSql.Provider.SqlServerForSystem", "Providers\FreeSql.Provider.SqlServerForSystem\FreeSql.Provider.SqlServerForSystem.csproj", "{3D2BD8EC-253A-437F-B4C8-74BC0D91429B}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FreeSql.Provider.SqlServerForSystem", "Providers\FreeSql.Provider.SqlServerForSystem\FreeSql.Provider.SqlServerForSystem.csproj", "{3D2BD8EC-253A-437F-B4C8-74BC0D91429B}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FreeSql.Extensions.AdoNet", "Extensions\FreeSql.Extensions.AdoNet\FreeSql.Extensions.AdoNet.csproj", "{774A7AAD-60F2-40E2-93E1-E74FC2C1BBFD}"
|
|
||||||
EndProject
|
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FreeSql.Tests.Extensions.AdoNet", "FreeSql.Tests\FreeSql.Tests.Extensions.AdoNet\FreeSql.Tests.Extensions.AdoNet.csproj", "{02B31331-9B6E-44D2-B135-38DAE92F8A40}"
|
|
||||||
EndProject
|
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
@ -532,30 +528,6 @@ Global
|
|||||||
{3D2BD8EC-253A-437F-B4C8-74BC0D91429B}.Release|x64.Build.0 = Release|Any CPU
|
{3D2BD8EC-253A-437F-B4C8-74BC0D91429B}.Release|x64.Build.0 = Release|Any CPU
|
||||||
{3D2BD8EC-253A-437F-B4C8-74BC0D91429B}.Release|x86.ActiveCfg = Release|Any CPU
|
{3D2BD8EC-253A-437F-B4C8-74BC0D91429B}.Release|x86.ActiveCfg = Release|Any CPU
|
||||||
{3D2BD8EC-253A-437F-B4C8-74BC0D91429B}.Release|x86.Build.0 = Release|Any CPU
|
{3D2BD8EC-253A-437F-B4C8-74BC0D91429B}.Release|x86.Build.0 = Release|Any CPU
|
||||||
{774A7AAD-60F2-40E2-93E1-E74FC2C1BBFD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
|
||||||
{774A7AAD-60F2-40E2-93E1-E74FC2C1BBFD}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
|
||||||
{774A7AAD-60F2-40E2-93E1-E74FC2C1BBFD}.Debug|x64.ActiveCfg = Debug|Any CPU
|
|
||||||
{774A7AAD-60F2-40E2-93E1-E74FC2C1BBFD}.Debug|x64.Build.0 = Debug|Any CPU
|
|
||||||
{774A7AAD-60F2-40E2-93E1-E74FC2C1BBFD}.Debug|x86.ActiveCfg = Debug|Any CPU
|
|
||||||
{774A7AAD-60F2-40E2-93E1-E74FC2C1BBFD}.Debug|x86.Build.0 = Debug|Any CPU
|
|
||||||
{774A7AAD-60F2-40E2-93E1-E74FC2C1BBFD}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
|
||||||
{774A7AAD-60F2-40E2-93E1-E74FC2C1BBFD}.Release|Any CPU.Build.0 = Release|Any CPU
|
|
||||||
{774A7AAD-60F2-40E2-93E1-E74FC2C1BBFD}.Release|x64.ActiveCfg = Release|Any CPU
|
|
||||||
{774A7AAD-60F2-40E2-93E1-E74FC2C1BBFD}.Release|x64.Build.0 = Release|Any CPU
|
|
||||||
{774A7AAD-60F2-40E2-93E1-E74FC2C1BBFD}.Release|x86.ActiveCfg = Release|Any CPU
|
|
||||||
{774A7AAD-60F2-40E2-93E1-E74FC2C1BBFD}.Release|x86.Build.0 = Release|Any CPU
|
|
||||||
{02B31331-9B6E-44D2-B135-38DAE92F8A40}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
|
||||||
{02B31331-9B6E-44D2-B135-38DAE92F8A40}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
|
||||||
{02B31331-9B6E-44D2-B135-38DAE92F8A40}.Debug|x64.ActiveCfg = Debug|Any CPU
|
|
||||||
{02B31331-9B6E-44D2-B135-38DAE92F8A40}.Debug|x64.Build.0 = Debug|Any CPU
|
|
||||||
{02B31331-9B6E-44D2-B135-38DAE92F8A40}.Debug|x86.ActiveCfg = Debug|Any CPU
|
|
||||||
{02B31331-9B6E-44D2-B135-38DAE92F8A40}.Debug|x86.Build.0 = Debug|Any CPU
|
|
||||||
{02B31331-9B6E-44D2-B135-38DAE92F8A40}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
|
||||||
{02B31331-9B6E-44D2-B135-38DAE92F8A40}.Release|Any CPU.Build.0 = Release|Any CPU
|
|
||||||
{02B31331-9B6E-44D2-B135-38DAE92F8A40}.Release|x64.ActiveCfg = Release|Any CPU
|
|
||||||
{02B31331-9B6E-44D2-B135-38DAE92F8A40}.Release|x64.Build.0 = Release|Any CPU
|
|
||||||
{02B31331-9B6E-44D2-B135-38DAE92F8A40}.Release|x86.ActiveCfg = Release|Any CPU
|
|
||||||
{02B31331-9B6E-44D2-B135-38DAE92F8A40}.Release|x86.Build.0 = Release|Any CPU
|
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
@ -586,7 +558,6 @@ Global
|
|||||||
{07AB0B37-A8B1-4FB1-9259-7B804E369E36} = {94C8A78D-AA15-47B2-A348-530CD86BFC1B}
|
{07AB0B37-A8B1-4FB1-9259-7B804E369E36} = {94C8A78D-AA15-47B2-A348-530CD86BFC1B}
|
||||||
{938173AF-157F-4040-AED3-171DA1809CAA} = {2A381C57-2697-427B-9F10-55DA11FD02E4}
|
{938173AF-157F-4040-AED3-171DA1809CAA} = {2A381C57-2697-427B-9F10-55DA11FD02E4}
|
||||||
{3D2BD8EC-253A-437F-B4C8-74BC0D91429B} = {2A381C57-2697-427B-9F10-55DA11FD02E4}
|
{3D2BD8EC-253A-437F-B4C8-74BC0D91429B} = {2A381C57-2697-427B-9F10-55DA11FD02E4}
|
||||||
{774A7AAD-60F2-40E2-93E1-E74FC2C1BBFD} = {4A92E8A6-9A6D-41A1-9CDA-DE10899648AA}
|
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
SolutionGuid = {089687FD-5D25-40AB-BA8A-A10D1E137F98}
|
SolutionGuid = {089687FD-5D25-40AB-BA8A-A10D1E137F98}
|
||||||
|
@ -7,6 +7,7 @@ using System.Collections.Concurrent;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Data;
|
using System.Data;
|
||||||
|
using System.Data.Common;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Linq.Expressions;
|
using System.Linq.Expressions;
|
||||||
@ -511,4 +512,265 @@ SELECT ");
|
|||||||
return newSelect;
|
return newSelect;
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region Ado.net 扩展方法,类似于 Dapper
|
||||||
|
|
||||||
|
static Dictionary<Type, IFreeSql> _dicCurd = new Dictionary<Type, IFreeSql>();
|
||||||
|
static object _dicCurdLock = new object();
|
||||||
|
static IFreeSql GetCrud(IDbConnection dbconn)
|
||||||
|
{
|
||||||
|
if (dbconn == null) throw new ArgumentNullException($"{nameof(dbconn)} 不能为 null"); ;
|
||||||
|
Type dbconType = dbconn.GetType();
|
||||||
|
var connType = dbconType.UnderlyingSystemType;
|
||||||
|
if (_dicCurd.TryGetValue(connType, out var fsql)) return fsql;
|
||||||
|
|
||||||
|
Type providerType = null;
|
||||||
|
switch (connType.Name)
|
||||||
|
{
|
||||||
|
case "MySqlConnection":
|
||||||
|
providerType = Type.GetType("FreeSql.MySql.MySqlProvider`1,FreeSql.Provider.MySql")?.MakeGenericType(connType);
|
||||||
|
if (providerType == null) providerType = Type.GetType("FreeSql.MySql.MySqlProvider`1,FreeSql.Provider.MySqlConnector")?.MakeGenericType(connType);
|
||||||
|
if (providerType == null) throw new Exception("缺少 FreeSql 数据库实现包:FreeSql.Provider.MySql.dll,可前往 nuget 下载");
|
||||||
|
break;
|
||||||
|
case "SqlConnection":
|
||||||
|
providerType = Type.GetType("FreeSql.SqlServer.SqlServerProvider`1,FreeSql.Provider.SqlServer")?.MakeGenericType(connType);
|
||||||
|
if (providerType == null) throw new Exception("缺少 FreeSql 数据库实现包:FreeSql.Provider.SqlServer.dll,可前往 nuget 下载");
|
||||||
|
break;
|
||||||
|
case "NpgsqlConnection":
|
||||||
|
providerType = Type.GetType("FreeSql.PostgreSQL.PostgreSQLProvider`1,FreeSql.Provider.PostgreSQL")?.MakeGenericType(connType);
|
||||||
|
if (providerType == null) throw new Exception("缺少 FreeSql 数据库实现包:FreeSql.Provider.PostgreSQL.dll,可前往 nuget 下载");
|
||||||
|
break;
|
||||||
|
case "OracleConnection":
|
||||||
|
providerType = Type.GetType("FreeSql.Oracle.OracleProvider`1,FreeSql.Provider.Oracle")?.MakeGenericType(connType);
|
||||||
|
if (providerType == null) throw new Exception("缺少 FreeSql 数据库实现包:FreeSql.Provider.Oracle.dll,可前往 nuget 下载");
|
||||||
|
break;
|
||||||
|
case "SQLiteConnection":
|
||||||
|
providerType = Type.GetType("FreeSql.Sqlite.SqliteProvider`1,FreeSql.Provider.Sqlite")?.MakeGenericType(connType);
|
||||||
|
if (providerType == null) throw new Exception("缺少 FreeSql 数据库实现包:FreeSql.Provider.Sqlite.dll,可前往 nuget 下载");
|
||||||
|
break;
|
||||||
|
case "DmConnection":
|
||||||
|
providerType = Type.GetType("FreeSql.Dameng.DamengProvider`1,FreeSql.Provider.Dameng")?.MakeGenericType(connType);
|
||||||
|
if (providerType == null) throw new Exception("缺少 FreeSql 数据库实现包:FreeSql.Provider.Dameng.dll,可前往 nuget 下载");
|
||||||
|
break;
|
||||||
|
case "OscarConnection":
|
||||||
|
providerType = Type.GetType("FreeSql.ShenTong.ShenTongProvider`1,FreeSql.Provider.ShenTong")?.MakeGenericType(connType);
|
||||||
|
if (providerType == null) throw new Exception("缺少 FreeSql 数据库实现包:FreeSql.Provider.ShenTong.dll,可前往 nuget 下载");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new Exception("未实现");
|
||||||
|
}
|
||||||
|
lock (_dicCurdLock)
|
||||||
|
{
|
||||||
|
if (_dicCurd.TryGetValue(connType, out fsql)) return fsql;
|
||||||
|
lock (_dicCurdLock)
|
||||||
|
_dicCurd.Add(connType, fsql = Activator.CreateInstance(providerType, new object[] { null, null, null }) as IFreeSql);
|
||||||
|
}
|
||||||
|
return fsql;
|
||||||
|
}
|
||||||
|
static IFreeSql GetCrud(IDbTransaction dbtran)
|
||||||
|
{
|
||||||
|
if (dbtran == null) throw new ArgumentNullException($"{nameof(dbtran)} 不能为 null");
|
||||||
|
return GetCrud(dbtran.Connection);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取 IDbConnection 对应的 IFreeSql 实例
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="that"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static IFreeSql GetIFreeSql(this IDbConnection that) => GetCrud(that);
|
||||||
|
|
||||||
|
#region IDbConnection
|
||||||
|
/// <summary>
|
||||||
|
/// 插入数据
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T1"></typeparam>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static IInsert<T1> Insert<T1>(this IDbConnection that) where T1 : class => GetCrud(that).Insert<T1>().WithConnection(that as DbConnection);
|
||||||
|
/// <summary>
|
||||||
|
/// 插入数据,传入实体
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T1"></typeparam>
|
||||||
|
/// <param name="source"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static IInsert<T1> Insert<T1>(this IDbConnection that, T1 source) where T1 : class => GetCrud(that).Insert<T1>(source).WithConnection(that as DbConnection);
|
||||||
|
/// <summary>
|
||||||
|
/// 插入数据,传入实体数组
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T1"></typeparam>
|
||||||
|
/// <param name="source"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static IInsert<T1> Insert<T1>(this IDbConnection that, T1[] source) where T1 : class => GetCrud(that).Insert<T1>(source).WithConnection(that as DbConnection);
|
||||||
|
/// <summary>
|
||||||
|
/// 插入数据,传入实体集合
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T1"></typeparam>
|
||||||
|
/// <param name="source"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static IInsert<T1> Insert<T1>(this IDbConnection that, List<T1> source) where T1 : class => GetCrud(that).Insert<T1>(source).WithConnection(that as DbConnection);
|
||||||
|
/// <summary>
|
||||||
|
/// 插入数据,传入实体集合
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T1"></typeparam>
|
||||||
|
/// <param name="source"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static IInsert<T1> Insert<T1>(this IDbConnection that, IEnumerable<T1> source) where T1 : class => GetCrud(that).Insert<T1>(source).WithConnection(that as DbConnection);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 插入或更新数据,此功能依赖数据库特性(低版本可能不支持),参考如下:<para></para>
|
||||||
|
/// MySql 5.6+: on duplicate key update<para></para>
|
||||||
|
/// PostgreSQL 9.4+: on conflict do update<para></para>
|
||||||
|
/// SqlServer 2008+: merge into<para></para>
|
||||||
|
/// Oracle 11+: merge into<para></para>
|
||||||
|
/// Sqlite: replace into<para></para>
|
||||||
|
/// 达梦: merge into<para></para>
|
||||||
|
/// 人大金仓:on conflict do update<para></para>
|
||||||
|
/// 神通:merge into<para></para>
|
||||||
|
/// MsAccess:不支持<para></para>
|
||||||
|
/// 注意区别:FreeSql.Repository 仓储也有 InsertOrUpdate 方法(不依赖数据库特性)
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T1"></typeparam>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static IInsertOrUpdate<T1> InsertOrUpdate<T1>(this IDbConnection that) where T1 : class => GetCrud(that).InsertOrUpdate<T1>().WithConnection(that as DbConnection);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 修改数据
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T1"></typeparam>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static IUpdate<T1> Update<T1>(this IDbConnection that) where T1 : class => GetCrud(that).Update<T1>().WithConnection(that as DbConnection);
|
||||||
|
/// <summary>
|
||||||
|
/// 修改数据,传入动态条件,如:主键值 | new[]{主键值1,主键值2} | TEntity1 | new[]{TEntity1,TEntity2} | new{id=1}
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T1"></typeparam>
|
||||||
|
/// <param name="dywhere">主键值、主键值集合、实体、实体集合、匿名对象、匿名对象集合</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static IUpdate<T1> Update<T1>(this IDbConnection that, object dywhere) where T1 : class => GetCrud(that).Update<T1>(dywhere).WithConnection(that as DbConnection);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 查询数据
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T1"></typeparam>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static ISelect<T1> Select<T1>(this IDbConnection that) where T1 : class => GetCrud(that).Select<T1>().WithConnection(that as DbConnection);
|
||||||
|
/// <summary>
|
||||||
|
/// 查询数据,传入动态条件,如:主键值 | new[]{主键值1,主键值2} | TEntity1 | new[]{TEntity1,TEntity2} | new{id=1}
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T1"></typeparam>
|
||||||
|
/// <param name="dywhere">主键值、主键值集合、实体、实体集合、匿名对象、匿名对象集合</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static ISelect<T1> Select<T1>(this IDbConnection that, object dywhere) where T1 : class => GetCrud(that).Select<T1>(dywhere).WithConnection(that as DbConnection);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 删除数据
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T1"></typeparam>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static IDelete<T1> Delete<T1>(this IDbConnection that) where T1 : class => GetCrud(that).Delete<T1>().WithConnection(that as DbConnection);
|
||||||
|
/// <summary>
|
||||||
|
/// 删除数据,传入动态条件,如:主键值 | new[]{主键值1,主键值2} | TEntity1 | new[]{TEntity1,TEntity2} | new{id=1}
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T1"></typeparam>
|
||||||
|
/// <param name="dywhere">主键值、主键值集合、实体、实体集合、匿名对象、匿名对象集合</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static IDelete<T1> Delete<T1>(this IDbConnection that, object dywhere) where T1 : class => GetCrud(that).Delete<T1>(dywhere).WithConnection(that as DbConnection);
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region IDbTransaction
|
||||||
|
/// <summary>
|
||||||
|
/// 插入数据
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T1"></typeparam>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static IInsert<T1> Insert<T1>(this IDbTransaction that) where T1 : class => GetCrud(that).Insert<T1>().WithTransaction(that as DbTransaction);
|
||||||
|
/// <summary>
|
||||||
|
/// 插入数据,传入实体
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T1"></typeparam>
|
||||||
|
/// <param name="source"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static IInsert<T1> Insert<T1>(this IDbTransaction that, T1 source) where T1 : class => GetCrud(that).Insert<T1>(source).WithTransaction(that as DbTransaction);
|
||||||
|
/// <summary>
|
||||||
|
/// 插入数据,传入实体数组
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T1"></typeparam>
|
||||||
|
/// <param name="source"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static IInsert<T1> Insert<T1>(this IDbTransaction that, T1[] source) where T1 : class => GetCrud(that).Insert<T1>(source).WithTransaction(that as DbTransaction);
|
||||||
|
/// <summary>
|
||||||
|
/// 插入数据,传入实体集合
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T1"></typeparam>
|
||||||
|
/// <param name="source"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static IInsert<T1> Insert<T1>(this IDbTransaction that, List<T1> source) where T1 : class => GetCrud(that).Insert<T1>(source).WithTransaction(that as DbTransaction);
|
||||||
|
/// <summary>
|
||||||
|
/// 插入数据,传入实体集合
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T1"></typeparam>
|
||||||
|
/// <param name="source"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static IInsert<T1> Insert<T1>(this IDbTransaction that, IEnumerable<T1> source) where T1 : class => GetCrud(that).Insert<T1>(source).WithTransaction(that as DbTransaction);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 插入或更新数据,此功能依赖数据库特性(低版本可能不支持),参考如下:<para></para>
|
||||||
|
/// MySql 5.6+: on duplicate key update<para></para>
|
||||||
|
/// PostgreSQL 9.4+: on conflict do update<para></para>
|
||||||
|
/// SqlServer 2008+: merge into<para></para>
|
||||||
|
/// Oracle 11+: merge into<para></para>
|
||||||
|
/// Sqlite: replace into<para></para>
|
||||||
|
/// 达梦: merge into<para></para>
|
||||||
|
/// 人大金仓:on conflict do update<para></para>
|
||||||
|
/// 神通:merge into<para></para>
|
||||||
|
/// MsAccess:不支持<para></para>
|
||||||
|
/// 注意区别:FreeSql.Repository 仓储也有 InsertOrUpdate 方法(不依赖数据库特性)
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T1"></typeparam>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static IInsertOrUpdate<T1> InsertOrUpdate<T1>(this IDbTransaction that) where T1 : class => GetCrud(that).InsertOrUpdate<T1>().WithTransaction(that as DbTransaction);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 修改数据
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T1"></typeparam>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static IUpdate<T1> Update<T1>(this IDbTransaction that) where T1 : class => GetCrud(that).Update<T1>().WithTransaction(that as DbTransaction);
|
||||||
|
/// <summary>
|
||||||
|
/// 修改数据,传入动态条件,如:主键值 | new[]{主键值1,主键值2} | TEntity1 | new[]{TEntity1,TEntity2} | new{id=1}
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T1"></typeparam>
|
||||||
|
/// <param name="dywhere">主键值、主键值集合、实体、实体集合、匿名对象、匿名对象集合</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static IUpdate<T1> Update<T1>(this IDbTransaction that, object dywhere) where T1 : class => GetCrud(that).Update<T1>(dywhere).WithTransaction(that as DbTransaction);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 查询数据
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T1"></typeparam>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static ISelect<T1> Select<T1>(this IDbTransaction that) where T1 : class => GetCrud(that).Select<T1>().WithTransaction(that as DbTransaction);
|
||||||
|
/// <summary>
|
||||||
|
/// 查询数据,传入动态条件,如:主键值 | new[]{主键值1,主键值2} | TEntity1 | new[]{TEntity1,TEntity2} | new{id=1}
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T1"></typeparam>
|
||||||
|
/// <param name="dywhere">主键值、主键值集合、实体、实体集合、匿名对象、匿名对象集合</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static ISelect<T1> Select<T1>(this IDbTransaction that, object dywhere) where T1 : class => GetCrud(that).Select<T1>(dywhere).WithTransaction(that as DbTransaction);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 删除数据
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T1"></typeparam>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static IDelete<T1> Delete<T1>(this IDbTransaction that) where T1 : class => GetCrud(that).Delete<T1>().WithTransaction(that as DbTransaction);
|
||||||
|
/// <summary>
|
||||||
|
/// 删除数据,传入动态条件,如:主键值 | new[]{主键值1,主键值2} | TEntity1 | new[]{TEntity1,TEntity2} | new{id=1}
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T1"></typeparam>
|
||||||
|
/// <param name="dywhere">主键值、主键值集合、实体、实体集合、匿名对象、匿名对象集合</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static IDelete<T1> Delete<T1>(this IDbTransaction that, object dywhere) where T1 : class => GetCrud(that).Delete<T1>(dywhere).WithTransaction(that as DbTransaction);
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#endregion
|
||||||
}
|
}
|
@ -3853,6 +3853,215 @@
|
|||||||
<param name="level">递归层级</param>
|
<param name="level">递归层级</param>
|
||||||
<returns></returns>
|
<returns></returns>
|
||||||
</member>
|
</member>
|
||||||
|
<member name="M:FreeSqlGlobalExtensions.GetIFreeSql(System.Data.IDbConnection)">
|
||||||
|
<summary>
|
||||||
|
获取 IDbConnection 对应的 IFreeSql 实例
|
||||||
|
</summary>
|
||||||
|
<param name="that"></param>
|
||||||
|
<returns></returns>
|
||||||
|
</member>
|
||||||
|
<member name="M:FreeSqlGlobalExtensions.Insert``1(System.Data.IDbConnection)">
|
||||||
|
<summary>
|
||||||
|
插入数据
|
||||||
|
</summary>
|
||||||
|
<typeparam name="T1"></typeparam>
|
||||||
|
<returns></returns>
|
||||||
|
</member>
|
||||||
|
<member name="M:FreeSqlGlobalExtensions.Insert``1(System.Data.IDbConnection,``0)">
|
||||||
|
<summary>
|
||||||
|
插入数据,传入实体
|
||||||
|
</summary>
|
||||||
|
<typeparam name="T1"></typeparam>
|
||||||
|
<param name="source"></param>
|
||||||
|
<returns></returns>
|
||||||
|
</member>
|
||||||
|
<member name="M:FreeSqlGlobalExtensions.Insert``1(System.Data.IDbConnection,``0[])">
|
||||||
|
<summary>
|
||||||
|
插入数据,传入实体数组
|
||||||
|
</summary>
|
||||||
|
<typeparam name="T1"></typeparam>
|
||||||
|
<param name="source"></param>
|
||||||
|
<returns></returns>
|
||||||
|
</member>
|
||||||
|
<member name="M:FreeSqlGlobalExtensions.Insert``1(System.Data.IDbConnection,System.Collections.Generic.List{``0})">
|
||||||
|
<summary>
|
||||||
|
插入数据,传入实体集合
|
||||||
|
</summary>
|
||||||
|
<typeparam name="T1"></typeparam>
|
||||||
|
<param name="source"></param>
|
||||||
|
<returns></returns>
|
||||||
|
</member>
|
||||||
|
<member name="M:FreeSqlGlobalExtensions.Insert``1(System.Data.IDbConnection,System.Collections.Generic.IEnumerable{``0})">
|
||||||
|
<summary>
|
||||||
|
插入数据,传入实体集合
|
||||||
|
</summary>
|
||||||
|
<typeparam name="T1"></typeparam>
|
||||||
|
<param name="source"></param>
|
||||||
|
<returns></returns>
|
||||||
|
</member>
|
||||||
|
<member name="M:FreeSqlGlobalExtensions.InsertOrUpdate``1(System.Data.IDbConnection)">
|
||||||
|
<summary>
|
||||||
|
插入或更新数据,此功能依赖数据库特性(低版本可能不支持),参考如下:<para></para>
|
||||||
|
MySql 5.6+: on duplicate key update<para></para>
|
||||||
|
PostgreSQL 9.4+: on conflict do update<para></para>
|
||||||
|
SqlServer 2008+: merge into<para></para>
|
||||||
|
Oracle 11+: merge into<para></para>
|
||||||
|
Sqlite: replace into<para></para>
|
||||||
|
达梦: merge into<para></para>
|
||||||
|
人大金仓:on conflict do update<para></para>
|
||||||
|
神通:merge into<para></para>
|
||||||
|
MsAccess:不支持<para></para>
|
||||||
|
注意区别:FreeSql.Repository 仓储也有 InsertOrUpdate 方法(不依赖数据库特性)
|
||||||
|
</summary>
|
||||||
|
<typeparam name="T1"></typeparam>
|
||||||
|
<returns></returns>
|
||||||
|
</member>
|
||||||
|
<member name="M:FreeSqlGlobalExtensions.Update``1(System.Data.IDbConnection)">
|
||||||
|
<summary>
|
||||||
|
修改数据
|
||||||
|
</summary>
|
||||||
|
<typeparam name="T1"></typeparam>
|
||||||
|
<returns></returns>
|
||||||
|
</member>
|
||||||
|
<member name="M:FreeSqlGlobalExtensions.Update``1(System.Data.IDbConnection,System.Object)">
|
||||||
|
<summary>
|
||||||
|
修改数据,传入动态条件,如:主键值 | new[]{主键值1,主键值2} | TEntity1 | new[]{TEntity1,TEntity2} | new{id=1}
|
||||||
|
</summary>
|
||||||
|
<typeparam name="T1"></typeparam>
|
||||||
|
<param name="dywhere">主键值、主键值集合、实体、实体集合、匿名对象、匿名对象集合</param>
|
||||||
|
<returns></returns>
|
||||||
|
</member>
|
||||||
|
<member name="M:FreeSqlGlobalExtensions.Select``1(System.Data.IDbConnection)">
|
||||||
|
<summary>
|
||||||
|
查询数据
|
||||||
|
</summary>
|
||||||
|
<typeparam name="T1"></typeparam>
|
||||||
|
<returns></returns>
|
||||||
|
</member>
|
||||||
|
<member name="M:FreeSqlGlobalExtensions.Select``1(System.Data.IDbConnection,System.Object)">
|
||||||
|
<summary>
|
||||||
|
查询数据,传入动态条件,如:主键值 | new[]{主键值1,主键值2} | TEntity1 | new[]{TEntity1,TEntity2} | new{id=1}
|
||||||
|
</summary>
|
||||||
|
<typeparam name="T1"></typeparam>
|
||||||
|
<param name="dywhere">主键值、主键值集合、实体、实体集合、匿名对象、匿名对象集合</param>
|
||||||
|
<returns></returns>
|
||||||
|
</member>
|
||||||
|
<member name="M:FreeSqlGlobalExtensions.Delete``1(System.Data.IDbConnection)">
|
||||||
|
<summary>
|
||||||
|
删除数据
|
||||||
|
</summary>
|
||||||
|
<typeparam name="T1"></typeparam>
|
||||||
|
<returns></returns>
|
||||||
|
</member>
|
||||||
|
<member name="M:FreeSqlGlobalExtensions.Delete``1(System.Data.IDbConnection,System.Object)">
|
||||||
|
<summary>
|
||||||
|
删除数据,传入动态条件,如:主键值 | new[]{主键值1,主键值2} | TEntity1 | new[]{TEntity1,TEntity2} | new{id=1}
|
||||||
|
</summary>
|
||||||
|
<typeparam name="T1"></typeparam>
|
||||||
|
<param name="dywhere">主键值、主键值集合、实体、实体集合、匿名对象、匿名对象集合</param>
|
||||||
|
<returns></returns>
|
||||||
|
</member>
|
||||||
|
<member name="M:FreeSqlGlobalExtensions.Insert``1(System.Data.IDbTransaction)">
|
||||||
|
<summary>
|
||||||
|
插入数据
|
||||||
|
</summary>
|
||||||
|
<typeparam name="T1"></typeparam>
|
||||||
|
<returns></returns>
|
||||||
|
</member>
|
||||||
|
<member name="M:FreeSqlGlobalExtensions.Insert``1(System.Data.IDbTransaction,``0)">
|
||||||
|
<summary>
|
||||||
|
插入数据,传入实体
|
||||||
|
</summary>
|
||||||
|
<typeparam name="T1"></typeparam>
|
||||||
|
<param name="source"></param>
|
||||||
|
<returns></returns>
|
||||||
|
</member>
|
||||||
|
<member name="M:FreeSqlGlobalExtensions.Insert``1(System.Data.IDbTransaction,``0[])">
|
||||||
|
<summary>
|
||||||
|
插入数据,传入实体数组
|
||||||
|
</summary>
|
||||||
|
<typeparam name="T1"></typeparam>
|
||||||
|
<param name="source"></param>
|
||||||
|
<returns></returns>
|
||||||
|
</member>
|
||||||
|
<member name="M:FreeSqlGlobalExtensions.Insert``1(System.Data.IDbTransaction,System.Collections.Generic.List{``0})">
|
||||||
|
<summary>
|
||||||
|
插入数据,传入实体集合
|
||||||
|
</summary>
|
||||||
|
<typeparam name="T1"></typeparam>
|
||||||
|
<param name="source"></param>
|
||||||
|
<returns></returns>
|
||||||
|
</member>
|
||||||
|
<member name="M:FreeSqlGlobalExtensions.Insert``1(System.Data.IDbTransaction,System.Collections.Generic.IEnumerable{``0})">
|
||||||
|
<summary>
|
||||||
|
插入数据,传入实体集合
|
||||||
|
</summary>
|
||||||
|
<typeparam name="T1"></typeparam>
|
||||||
|
<param name="source"></param>
|
||||||
|
<returns></returns>
|
||||||
|
</member>
|
||||||
|
<member name="M:FreeSqlGlobalExtensions.InsertOrUpdate``1(System.Data.IDbTransaction)">
|
||||||
|
<summary>
|
||||||
|
插入或更新数据,此功能依赖数据库特性(低版本可能不支持),参考如下:<para></para>
|
||||||
|
MySql 5.6+: on duplicate key update<para></para>
|
||||||
|
PostgreSQL 9.4+: on conflict do update<para></para>
|
||||||
|
SqlServer 2008+: merge into<para></para>
|
||||||
|
Oracle 11+: merge into<para></para>
|
||||||
|
Sqlite: replace into<para></para>
|
||||||
|
达梦: merge into<para></para>
|
||||||
|
人大金仓:on conflict do update<para></para>
|
||||||
|
神通:merge into<para></para>
|
||||||
|
MsAccess:不支持<para></para>
|
||||||
|
注意区别:FreeSql.Repository 仓储也有 InsertOrUpdate 方法(不依赖数据库特性)
|
||||||
|
</summary>
|
||||||
|
<typeparam name="T1"></typeparam>
|
||||||
|
<returns></returns>
|
||||||
|
</member>
|
||||||
|
<member name="M:FreeSqlGlobalExtensions.Update``1(System.Data.IDbTransaction)">
|
||||||
|
<summary>
|
||||||
|
修改数据
|
||||||
|
</summary>
|
||||||
|
<typeparam name="T1"></typeparam>
|
||||||
|
<returns></returns>
|
||||||
|
</member>
|
||||||
|
<member name="M:FreeSqlGlobalExtensions.Update``1(System.Data.IDbTransaction,System.Object)">
|
||||||
|
<summary>
|
||||||
|
修改数据,传入动态条件,如:主键值 | new[]{主键值1,主键值2} | TEntity1 | new[]{TEntity1,TEntity2} | new{id=1}
|
||||||
|
</summary>
|
||||||
|
<typeparam name="T1"></typeparam>
|
||||||
|
<param name="dywhere">主键值、主键值集合、实体、实体集合、匿名对象、匿名对象集合</param>
|
||||||
|
<returns></returns>
|
||||||
|
</member>
|
||||||
|
<member name="M:FreeSqlGlobalExtensions.Select``1(System.Data.IDbTransaction)">
|
||||||
|
<summary>
|
||||||
|
查询数据
|
||||||
|
</summary>
|
||||||
|
<typeparam name="T1"></typeparam>
|
||||||
|
<returns></returns>
|
||||||
|
</member>
|
||||||
|
<member name="M:FreeSqlGlobalExtensions.Select``1(System.Data.IDbTransaction,System.Object)">
|
||||||
|
<summary>
|
||||||
|
查询数据,传入动态条件,如:主键值 | new[]{主键值1,主键值2} | TEntity1 | new[]{TEntity1,TEntity2} | new{id=1}
|
||||||
|
</summary>
|
||||||
|
<typeparam name="T1"></typeparam>
|
||||||
|
<param name="dywhere">主键值、主键值集合、实体、实体集合、匿名对象、匿名对象集合</param>
|
||||||
|
<returns></returns>
|
||||||
|
</member>
|
||||||
|
<member name="M:FreeSqlGlobalExtensions.Delete``1(System.Data.IDbTransaction)">
|
||||||
|
<summary>
|
||||||
|
删除数据
|
||||||
|
</summary>
|
||||||
|
<typeparam name="T1"></typeparam>
|
||||||
|
<returns></returns>
|
||||||
|
</member>
|
||||||
|
<member name="M:FreeSqlGlobalExtensions.Delete``1(System.Data.IDbTransaction,System.Object)">
|
||||||
|
<summary>
|
||||||
|
删除数据,传入动态条件,如:主键值 | new[]{主键值1,主键值2} | TEntity1 | new[]{TEntity1,TEntity2} | new{id=1}
|
||||||
|
</summary>
|
||||||
|
<typeparam name="T1"></typeparam>
|
||||||
|
<param name="dywhere">主键值、主键值集合、实体、实体集合、匿名对象、匿名对象集合</param>
|
||||||
|
<returns></returns>
|
||||||
|
</member>
|
||||||
<member name="M:System.Linq.Expressions.LambadaExpressionExtensions.And``1(System.Linq.Expressions.Expression{System.Func{``0,System.Boolean}},System.Linq.Expressions.Expression{System.Func{``0,System.Boolean}})">
|
<member name="M:System.Linq.Expressions.LambadaExpressionExtensions.And``1(System.Linq.Expressions.Expression{System.Func{``0,System.Boolean}},System.Linq.Expressions.Expression{System.Func{``0,System.Boolean}})">
|
||||||
<summary>
|
<summary>
|
||||||
使用 and 拼接两个 lambda 表达式
|
使用 and 拼接两个 lambda 表达式
|
||||||
|
Loading…
x
Reference in New Issue
Block a user