├── 函数处理.xlsx
├── Resource
└── icon.jpg
├── Core.Test
├── appsettings.json
├── appsettings.Development.json
├── Program.cs
├── Core.Test.csproj
├── Properties
│ └── launchSettings.json
├── FlowOrder.cs
├── Startup.cs
└── Controllers
│ └── ValuesController.cs
├── Kogel.Dapper.Extension
├── Entites
│ ├── EOrderBy.cs
│ ├── EOperateType.cs
│ ├── EFuzzyLocation.cs
│ ├── DataBaseContext.cs
│ ├── Navigation.cs
│ ├── DynamicTree.cs
│ ├── PageList.cs
│ └── JoinAssTable.cs
├── Exception
│ └── DapperExtensionException.cs
├── Dapper
│ ├── SqlMapper.DontMap.cs
│ ├── ExplicitConstructorAttribute.cs
│ ├── SqlMapper.DeserializerState.cs
│ ├── SqlMapper.IParameterCallbacks.cs
│ ├── DataTableHandler.cs
│ ├── DynamicParameters.CachedOutputSetters.cs
│ ├── SqlDataRecordHandler.cs
│ ├── SqlMapper.IParameterLookup.cs
│ ├── WrappedDataReader.cs
│ ├── SqlMapper.CacheInfo.cs
│ ├── SqlMapper.ICustomQueryParameter.cs
│ ├── CommandFlags.cs
│ ├── SqlMapper.IDynamicParameters.cs
│ ├── SqlMapper.LiteralToken.cs
│ ├── DynamicParameters.ParamInfo.cs
│ ├── SqlMapper.IMemberMap.cs
│ ├── SqlMapper.ITypeHandler.cs
│ ├── FeatureSupport.cs
│ ├── XmlHandlers.cs
│ ├── SqlMapper.TypeHandlerCache.cs
│ ├── SqlDataRecordListTVPParameter.cs
│ ├── UdtTypeHandler.cs
│ ├── SqlMapper.ITypeMap.cs
│ ├── SqlMapper.DapperTable.cs
│ ├── SqlMapper.Link.cs
│ ├── CustomPropertyTypeMap.cs
│ ├── SimpleMemberMap.cs
│ ├── TableValuedParameter.cs
│ ├── DbString.cs
│ ├── TypeExtensions.cs
│ ├── SqlMapper.TypeHandler.cs
│ ├── SqlMapper.DapperRowMetaObject.cs
│ └── WrappedReader.cs
├── Attributes
│ ├── StringLength.cs
│ ├── Identity.cs
│ ├── BaseAttrbute.cs
│ ├── ForeignKey.cs
│ └── Display.cs
├── Core
│ ├── Interfaces
│ │ ├── ICommandSet.cs
│ │ ├── IQuerySet.Select.cs
│ │ ├── ICodeFirst.cs
│ │ ├── IAggregation.cs
│ │ ├── ICommand.cs
│ │ ├── IQuerySet.Order.cs
│ │ ├── IQuerySet.SelectFrom.cs
│ │ ├── IDapperSet.cs
│ │ └── IQuerySet.Where.cs
│ ├── SetQ
│ │ ├── QuerySet.Select.cs
│ │ ├── QuerySet.Order.cs
│ │ ├── Aggregation.cs
│ │ ├── QuerySet.SelectFrom.cs
│ │ └── QuerySet.Where.cs
│ └── SetC
│ │ └── CommandSet.cs
├── Extension
│ ├── From
│ │ └── IBaseEntity.cs
│ └── ExpressExpansion.cs
├── Expressions
│ ├── ExpressionModifier.cs
│ ├── NavigationExpression.cs
│ ├── GroupExpression.cs
│ ├── ExpressionBuilder.cs
│ ├── WhereExpression.cs
│ └── UpdateExpression.cs
├── Helper
│ ├── TypeHelper.cs
│ ├── Function.cs
│ ├── Cache
│ │ └── EntityCache.cs
│ └── VersionCompatible.cs
├── AopProvider.cs
└── Kogel.Dapper.Extension.csproj
├── Kogel.Dapper.Extension.Test
├── Dto
│ ├── TestDto.cs
│ ├── AppConfigDto1.cs
│ └── OrderResDto.cs
├── Model
│ ├── Test.cs
│ ├── Dto
│ │ └── FlowOrderDto.cs
│ ├── Digiwin
│ │ └── TAM_SERIAL_NO_CREATE_BAS.cs
│ ├── LikeRecord.cs
│ ├── ProductWay.cs
│ ├── AppConfig.cs
│ ├── FlowOrder.cs
│ └── HeadOrder.cs
├── packages.config
├── UnitTest
│ ├── Mysql
│ │ └── Repository
│ │ │ ├── FlowOrderRepository.cs
│ │ │ └── IBaseRepository.cs
│ ├── Mssql
│ │ ├── Command.cs
│ │ └── Query.cs
│ └── Oracle
│ │ ├── Query.cs
│ │ └── Command.cs
├── Properties
│ ├── AssemblyInfo.cs
│ └── app.manifest
├── DbContextTest.cs
├── Program.cs
└── App.config
├── README.md
├── Kogel.Repository
├── Entites
│ ├── ProviderPool.cs
│ ├── ProviderOptions.cs
│ ├── ConnectionOptions.cs
│ └── ConnectionPool.cs
├── Interfaces
│ ├── IUnitOfWork.cs
│ └── IBaseRepository.cs
├── Global.cs
├── DependencyInjection.cs
└── Kogel.Repository.csproj
├── Kogel.Dapper.Extension.Mssql
├── Kogel.Dapper.Extension.Mssql.csproj
├── DataBase.cs
└── Extension
│ └── QueryExtension.cs
├── Kogel.Dapper.Extension.MySql
├── Kogel.Dapper.Extension.MySql.csproj
├── DataBase.cs
└── Extension
│ └── QueryExtension.cs
├── Kogel.Dapper.Extension.Oracle
├── Kogel.Dapper.Extension.Oracle.csproj
├── Extension
│ └── QueryExtension.cs
└── DataBase.cs
├── Kogel.Dapper.Extension.SQLite
├── Kogel.Dapper.Extension.SQLite.csproj
├── DataBase.cs
└── Extension
│ └── QueryExtension.cs
└── .gitattributes
/函数处理.xlsx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kogel-net/Kogel.Dapper.Extension/HEAD/函数处理.xlsx
--------------------------------------------------------------------------------
/Resource/icon.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kogel-net/Kogel.Dapper.Extension/HEAD/Resource/icon.jpg
--------------------------------------------------------------------------------
/Core.Test/appsettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "Logging": {
3 | "LogLevel": {
4 | "Default": "Warning"
5 | }
6 | },
7 | "AllowedHosts": "*"
8 | }
9 |
--------------------------------------------------------------------------------
/Kogel.Dapper.Extension/Entites/EOrderBy.cs:
--------------------------------------------------------------------------------
1 | namespace Kogel.Dapper.Extension.Entites
2 | {
3 | public enum EOrderBy
4 | {
5 | Asc = 1,
6 | Desc = -1
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/Kogel.Dapper.Extension/Entites/EOperateType.cs:
--------------------------------------------------------------------------------
1 | namespace Kogel.Dapper.Extension.Entites
2 | {
3 | public enum EOperateType
4 | {
5 | Query,
6 | Command
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/Core.Test/appsettings.Development.json:
--------------------------------------------------------------------------------
1 | {
2 | "Logging": {
3 | "LogLevel": {
4 | "Default": "Debug",
5 | "System": "Information",
6 | "Microsoft": "Information"
7 | }
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/Kogel.Dapper.Extension.Test/Dto/TestDto.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace Kogel.Dapper.Extension.Test.Model
8 | {
9 | public class TestDto
10 | {
11 |
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/Kogel.Dapper.Extension.Test/Model/Test.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using Kogel.Dapper.Extension.Attributes;
7 |
8 | namespace Kogel.Dapper.Extension.Test.Model
9 | {
10 |
11 |
12 | }
13 |
--------------------------------------------------------------------------------
/Kogel.Dapper.Extension/Exception/DapperExtensionException.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Kogel.Dapper.Extension
4 | {
5 | public class DapperExtensionException : Exception
6 | {
7 | public DapperExtensionException(string msg) : base(msg)
8 | {
9 |
10 | }
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/Kogel.Dapper.Extension.Test/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Kogel.Dapper.Extension/Entites/EFuzzyLocation.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace Kogel.Dapper.Extension.Entites
8 | {
9 | public enum EFuzzyLocation
10 | {
11 | Left,
12 | Right,
13 | Both
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/Kogel.Dapper.Extension/Dapper/SqlMapper.DontMap.cs:
--------------------------------------------------------------------------------
1 | using Kogel.Dapper.Extension;
2 |
3 | namespace Kogel.Dapper.Extension
4 | {
5 | public static partial class SqlMapper
6 | {
7 | ///
8 | /// Dummy type for excluding from multi-map
9 | ///
10 | public class DontMap : IBaseEntity
11 | { /* hiding constructor */
12 | public override int Id { get; set; }
13 | }
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/Kogel.Dapper.Extension/Dapper/ExplicitConstructorAttribute.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Kogel.Dapper.Extension
4 | {
5 | ///
6 | /// Tell Dapper to use an explicit constructor, passing nulls or 0s for all parameters
7 | ///
8 | [AttributeUsage(AttributeTargets.Constructor, AllowMultiple = false)]
9 | public sealed class ExplicitConstructorAttribute : Attribute
10 | {
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/Kogel.Dapper.Extension.Test/UnitTest/Mysql/Repository/FlowOrderRepository.cs:
--------------------------------------------------------------------------------
1 | using Kogel.Dapper.Extension.Test.Model;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 |
8 | namespace Kogel.Dapper.Extension.Test.UnitTest.Mysql.Repository
9 | {
10 | public class FlowOrderRepository : IBaseRepository
11 | {
12 |
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/Kogel.Dapper.Extension/Attributes/StringLength.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace Kogel.Dapper.Extension.Attributes
6 | {
7 | public class StringLength : BaseAttrbute
8 | {
9 | ///
10 | /// 字段长度
11 | ///
12 | /// 字段长度
13 | public StringLength(int Length)
14 | {
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/Kogel.Dapper.Extension.Test/Model/Dto/FlowOrderDto.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace Kogel.Dapper.Extension.Test.Model.Dto
8 | {
9 | public class FlowOrderDto
10 | {
11 | public int Id { get; set; }
12 |
13 |
14 | public bool flowOrders1 { get; set; }
15 |
16 |
17 | public bool flowOrders2 { get; set; }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/Kogel.Dapper.Extension/Attributes/Identity.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace Kogel.Dapper.Extension.Attributes
6 | {
7 | public class Identity : BaseAttrbute
8 | {
9 | ///
10 | /// 是否自增
11 | ///
12 | public bool IsIncrease { get; set; }
13 | public Identity(bool IsIncrease = true)
14 | {
15 | this.IsIncrease = IsIncrease;
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 | # 介绍
3 |
4 | 此框架是Dapper的扩展,效率优于EntityFramwork,并且支持.NetFramework和.NetCore框架
5 |
6 | Koge.Dapper.Extension是一个小型库,通过为POCO添加基本的CRUD操作(获取,插入,更新,删除)来补充Dapper。对于更高级的查询方案,Kogel.Dapper.Extension提供了谓词系统。该库的目的是通过不需要任何属性或基类继承来保持POCO的纯净。
7 |
8 | 通过ClassMapper实现自定义映射。
9 |
10 | 支持Mssql,Oracle,Mysql等数据库
11 |
12 | 支持.net framework4.5,.net core2.0及以上
13 |
14 | 应用层需要引用包Kogel.Dapper.Extension.MsSql(如果数据库是Oracle则引用Kogel.Dapper.Extension.Oracle),Nuget上可以下载安装。
15 |
16 | 文档地址:https://www.cnblogs.com/kogel/p/10805696.html
17 |
18 | 或者百度,谷歌直接搜索Dapper Linq
--------------------------------------------------------------------------------
/Kogel.Dapper.Extension/Attributes/BaseAttrbute.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace Kogel.Dapper.Extension.Attributes
6 | {
7 | public class BaseAttrbute : Attribute
8 | {
9 | public string Name { get; set; }
10 | public string Description { get; set; }
11 |
12 | public BaseAttrbute(string Name = null, string Description = null)
13 | {
14 | this.Name = Name;
15 | this.Description = Description;
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/Kogel.Dapper.Extension/Dapper/SqlMapper.DeserializerState.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Data;
3 |
4 | namespace Kogel.Dapper.Extension
5 | {
6 | public static partial class SqlMapper
7 | {
8 | internal struct DeserializerState
9 | {
10 | public readonly int Hash;
11 | public readonly Func Func;
12 |
13 | public DeserializerState(int hash, Func func)
14 | {
15 | Hash = hash;
16 | Func = func;
17 | }
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/Kogel.Dapper.Extension/Dapper/SqlMapper.IParameterCallbacks.cs:
--------------------------------------------------------------------------------
1 | namespace Kogel.Dapper.Extension
2 | {
3 | public static partial class SqlMapper
4 | {
5 | ///
6 | /// Extends IDynamicParameters with facilities for executing callbacks after commands have completed
7 | ///
8 | public interface IParameterCallbacks : IDynamicParameters
9 | {
10 | ///
11 | /// Invoked when the command has executed
12 | ///
13 | void OnCompleted();
14 | }
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/Kogel.Dapper.Extension/Dapper/DataTableHandler.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Data;
3 | #if !NETSTANDARD1_3
4 | namespace Kogel.Dapper.Extension
5 | {
6 | internal sealed class DataTableHandler : SqlMapper.ITypeHandler
7 | {
8 | public object Parse(Type destinationType, object value)
9 | {
10 | throw new NotImplementedException();
11 | }
12 |
13 | public void SetValue(IDbDataParameter parameter, object value)
14 | {
15 | TableValuedParameter.Set(parameter, value as DataTable, null);
16 | }
17 | }
18 | }
19 | #endif
--------------------------------------------------------------------------------
/Kogel.Repository/Entites/ProviderPool.cs:
--------------------------------------------------------------------------------
1 | using Kogel.Dapper.Extension;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 |
8 | namespace Kogel.Repository.Entites
9 | {
10 | public class ProviderPool
11 | {
12 | ///
13 | ///
14 | ///
15 | public Func FuncProvider { get; set; }
16 |
17 | ///
18 | /// 自定义名称
19 | ///
20 | public string DbName { get; set; }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/Kogel.Dapper.Extension/Core/Interfaces/ICommandSet.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq.Expressions;
4 |
5 | namespace Kogel.Dapper.Extension.Core.Interfaces
6 | {
7 | public interface ICommandSet : ICommand
8 | {
9 | ICommandSet Where(Expression> predicate);
10 |
11 | ICommandSet Where(string sqlWhere, object param = null);
12 |
13 | ICommandSet WhereIf(bool where, Expression> truePredicate, Expression> falsePredicate);
14 |
15 | ICommandSet ResetTableName(Type type, string tableName);
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/Kogel.Dapper.Extension/Entites/DataBaseContext.cs:
--------------------------------------------------------------------------------
1 | using Kogel.Dapper.Extension.Core.SetC;
2 | using Kogel.Dapper.Extension.Core.SetQ;
3 | using Kogel.Dapper.Extension.Entites;
4 |
5 | namespace Kogel.Dapper.Extension
6 | {
7 | public class DataBaseContext : AbstractDataBaseContext
8 | {
9 | public QuerySet QuerySet => (QuerySet)Set;
10 |
11 | public CommandSet CommandSet => (CommandSet)Set;
12 | }
13 |
14 | public abstract class AbstractDataBaseContext
15 | {
16 | public AbstractSet Set { get; set; }
17 |
18 | public EOperateType OperateType { get; set; }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/Kogel.Dapper.Extension/Dapper/DynamicParameters.CachedOutputSetters.cs:
--------------------------------------------------------------------------------
1 | using System.Collections;
2 |
3 | namespace Kogel.Dapper.Extension
4 | {
5 | public partial class DynamicParameters
6 | {
7 | // The type here is used to differentiate the cache by type via generics
8 | // ReSharper disable once UnusedTypeParameter
9 | internal static class CachedOutputSetters
10 | {
11 | // Intentional, abusing generics to get our cache splits
12 | // ReSharper disable once StaticMemberInGenericType
13 | public static readonly Hashtable Cache = new Hashtable();
14 | }
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/Kogel.Dapper.Extension/Core/Interfaces/IQuerySet.Select.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Linq.Expressions;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 |
8 | namespace Kogel.Dapper.Extension.Core.Interfaces
9 | {
10 | public interface IQuerySet : IQuerySet
11 | {
12 | ///
13 | ///
14 | ///
15 | ///
16 | ///
17 | ///
18 | IQuery Select(Expression> select);
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/Kogel.Dapper.Extension/Dapper/SqlDataRecordHandler.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Data;
4 |
5 | namespace Kogel.Dapper.Extension
6 | {
7 | internal sealed class SqlDataRecordHandler : SqlMapper.ITypeHandler
8 | {
9 | public object Parse(Type destinationType, object value)
10 | {
11 | throw new NotSupportedException();
12 | }
13 |
14 | public void SetValue(IDbDataParameter parameter, object value)
15 | {
16 | SqlDataRecordListTVPParameter.Set(parameter, value as IEnumerable, null);
17 | }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/Kogel.Dapper.Extension/Dapper/SqlMapper.IParameterLookup.cs:
--------------------------------------------------------------------------------
1 | namespace Kogel.Dapper.Extension
2 | {
3 | public static partial class SqlMapper
4 | {
5 | ///
6 | /// Extends IDynamicParameters providing by-name lookup of parameter values
7 | ///
8 | public interface IParameterLookup : IDynamicParameters
9 | {
10 | ///
11 | /// Get the value of the specified parameter (return null if not found)
12 | ///
13 | /// The name of the parameter to get.
14 | object this[string name] { get; }
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/Kogel.Dapper.Extension/Dapper/WrappedDataReader.cs:
--------------------------------------------------------------------------------
1 | using System.Data;
2 |
3 | namespace Kogel.Dapper.Extension
4 | {
5 | ///
6 | /// Describes a reader that controls the lifetime of both a command and a reader,
7 | /// exposing the downstream command/reader as properties.
8 | ///
9 | public interface IWrappedDataReader : IDataReader
10 | {
11 | ///
12 | /// Obtain the underlying reader
13 | ///
14 | IDataReader Reader { get; }
15 | ///
16 | /// Obtain the underlying command
17 | ///
18 | IDbCommand Command { get; }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/Core.Test/Program.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.AspNetCore;
2 | using Microsoft.AspNetCore.Hosting;
3 | using Microsoft.Extensions.Configuration;
4 | using Microsoft.Extensions.Logging;
5 | using System;
6 | using System.Collections.Generic;
7 | using System.IO;
8 | using System.Linq;
9 | using System.Threading.Tasks;
10 |
11 | namespace Core.Test
12 | {
13 | public class Program
14 | {
15 | public static void Main(string[] args)
16 | {
17 | CreateWebHostBuilder(args).Build().Run();
18 | }
19 |
20 | public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
21 | WebHost.CreateDefaultBuilder(args)
22 | .UseStartup();
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/Kogel.Repository/Entites/ProviderOptions.cs:
--------------------------------------------------------------------------------
1 | using Kogel.Dapper.Extension;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 |
8 | namespace Kogel.Repository.Entites
9 | {
10 | public class ProviderOptions
11 | {
12 | ///
13 | ///
14 | ///
15 | public Func Provider { get; set; }
16 |
17 | ///
18 | /// 数据库名称
19 | ///
20 | public string DbName { get; set; }
21 |
22 | ///
23 | /// 是否是主链接
24 | ///
25 | public bool IsCurrent { get; set; }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/Kogel.Dapper.Extension/Dapper/SqlMapper.CacheInfo.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Data;
3 | using System.Threading;
4 |
5 | namespace Kogel.Dapper.Extension
6 | {
7 | public static partial class SqlMapper
8 | {
9 | internal class CacheInfo
10 | {
11 | public DeserializerState Deserializer { get; set; }
12 | public Func[] OtherDeserializers { get; set; }
13 | public Action ParamReader { get; set; }
14 | private int hitCount;
15 | public int GetHitCount() { return Interlocked.CompareExchange(ref hitCount, 0, 0); }
16 | public void RecordHit() { Interlocked.Increment(ref hitCount); }
17 | }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/Kogel.Repository/Entites/ConnectionOptions.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Data;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 |
8 | namespace Kogel.Repository.Entites
9 | {
10 | ///
11 | ///
12 | ///
13 | public class ConnectionOptions
14 | {
15 | ///
16 | ///
17 | ///
18 | public IDbConnection Connection { get; set; }
19 |
20 | ///
21 | /// 数据库名称
22 | ///
23 | public string DbName { get; set; }
24 |
25 | ///
26 | /// 是否是主链接
27 | ///
28 | public bool IsCurrent { get; set; }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/Kogel.Dapper.Extension/Dapper/SqlMapper.ICustomQueryParameter.cs:
--------------------------------------------------------------------------------
1 | using System.Data;
2 |
3 | namespace Kogel.Dapper.Extension
4 | {
5 | public static partial class SqlMapper
6 | {
7 | ///
8 | /// Implement this interface to pass an arbitrary db specific parameter to Dapper
9 | ///
10 | public interface ICustomQueryParameter
11 | {
12 | ///
13 | /// Add the parameter needed to the command before it executes
14 | ///
15 | /// The raw command prior to execution
16 | /// Parameter name
17 | void AddParameter(IDbCommand command, string name);
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/Kogel.Dapper.Extension/Dapper/CommandFlags.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Kogel.Dapper.Extension
4 | {
5 | ///
6 | /// Additional state flags that control command behaviour
7 | ///
8 | [Flags]
9 | public enum CommandFlags
10 | {
11 | ///
12 | /// No additional flags
13 | ///
14 | None = 0,
15 | ///
16 | /// Should data be buffered before returning?
17 | ///
18 | Buffered = 1,
19 | ///
20 | /// Can async queries be pipelined?
21 | ///
22 | Pipelined = 2,
23 | ///
24 | /// Should the plan cache be bypassed?
25 | ///
26 | NoCache = 4,
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/Kogel.Dapper.Extension/Dapper/SqlMapper.IDynamicParameters.cs:
--------------------------------------------------------------------------------
1 | using System.Data;
2 |
3 | namespace Kogel.Dapper.Extension
4 | {
5 | public static partial class SqlMapper
6 | {
7 | ///
8 | /// Implement this interface to pass an arbitrary db specific set of parameters to Dapper
9 | ///
10 | public interface IDynamicParameters
11 | {
12 | ///
13 | /// Add all the parameters needed to the command just before it executes
14 | ///
15 | /// The raw command prior to execution
16 | /// Information about the query
17 | void AddParameters(IDbCommand command, Identity identity);
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/Kogel.Dapper.Extension/Attributes/ForeignKey.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace Kogel.Dapper.Extension.Attributes
8 | {
9 | ///
10 | /// 导航关联
11 | ///
12 | public class ForeignKey : Attribute
13 | {
14 | ///
15 | /// 索引字段
16 | ///
17 | public string IndexField { get; set; }
18 | ///
19 | /// (导航表)关联字段
20 | ///
21 | public string AssoField { get; set; }
22 | ///
23 | /// 导航关联
24 | ///
25 | /// 索引字段
26 | /// (导航表)关联字段
27 | public ForeignKey(string IndexField, string AssoField)
28 | {
29 | this.IndexField = IndexField;
30 | this.AssoField = AssoField;
31 | }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/Kogel.Dapper.Extension.Test/UnitTest/Mssql/Command.cs:
--------------------------------------------------------------------------------
1 | using Kogel.Repository;
2 | using System;
3 | using System.Data.SqlClient;
4 | using Kogel.Dapper.Extension.Attributes;
5 | using Kogel.Dapper.Extension.MsSql;
6 |
7 | namespace Kogel.Dapper.Extension.Test.UnitTest.Mssql
8 | {
9 | public class Command
10 | {
11 | public void Test()
12 | {
13 |
14 | }
15 | }
16 |
17 | ///
18 | ///
19 | ///
20 | [Display(Rename = "test")]
21 | public class Test
22 | {
23 | ///
24 | ///
25 | ///
26 | [Identity]
27 | [Display(Rename = "id")]
28 | public int Id { get; set; }
29 |
30 | ///
31 | ///
32 | ///
33 | [Display(Rename = "name")]
34 | public string Name { get; set; }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/Kogel.Dapper.Extension/Extension/From/IBaseEntity.cs:
--------------------------------------------------------------------------------
1 | using Kogel.Dapper.Extension.Attributes;
2 | using System;
3 |
4 | namespace Kogel.Dapper.Extension
5 | {
6 | ///
7 | /// 父级实体类
8 | ///
9 | ///
10 | ///
11 | public abstract class IBaseEntity : IBaseEntity
12 | {
13 | ///
14 | /// 主键id
15 | ///
16 | [Identity]
17 | public virtual TKey Id { get; set; }
18 | ///
19 | /// 获取主键值
20 | ///
21 | ///
22 | public object GetId()
23 | {
24 | return this.Id;
25 | }
26 | }
27 |
28 | public interface IBaseEntity
29 | {
30 | object GetId();
31 | }
32 |
33 | public class IBaseEntityDto : IBaseEntity
34 | {
35 | public object GetId()
36 | {
37 | return null;
38 | }
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/Core.Test/Core.Test.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netcoreapp2.1
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/Kogel.Dapper.Extension.Test/Model/Digiwin/TAM_SERIAL_NO_CREATE_BAS.cs:
--------------------------------------------------------------------------------
1 | using Digiwin.MES.Server.Infrastructure.Core.DataBase.Model;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 |
8 | namespace Kogel.Dapper.Extension.Test.Model.Digiwin
9 | {
10 | public class TAM_SERIAL_NO_CREATE_BAS : EntityBase
11 | {
12 | ///
13 | /// 设备工序GUID
14 | ///
15 | public string SERIAL_GUID { get; set; }
16 | ///
17 | /// 工装GUID
18 | ///
19 | public string CLASS_GUID { get; set; }
20 | ///
21 | /// 组号
22 | ///
23 | public string GROUP_NO { get; set; }
24 | ///
25 | /// 流水号
26 | ///
27 | public decimal SERIAL_NUMBER { get; set; }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/Core.Test/Properties/launchSettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "http://json.schemastore.org/launchsettings.json",
3 | "iisSettings": {
4 | "windowsAuthentication": false,
5 | "anonymousAuthentication": true,
6 | "iisExpress": {
7 | "applicationUrl": "http://localhost:61208",
8 | "sslPort": 44392
9 | }
10 | },
11 | "profiles": {
12 | "IIS Express": {
13 | "commandName": "IISExpress",
14 | "launchBrowser": true,
15 | "launchUrl": "api/values",
16 | "environmentVariables": {
17 | "ASPNETCORE_ENVIRONMENT": "Development"
18 | }
19 | },
20 | "Core.Test": {
21 | "commandName": "Project",
22 | "launchBrowser": true,
23 | "launchUrl": "api/values",
24 | "applicationUrl": "https://localhost:5001;http://localhost:5000",
25 | "environmentVariables": {
26 | "ASPNETCORE_ENVIRONMENT": "Development"
27 | }
28 | }
29 | }
30 | }
--------------------------------------------------------------------------------
/Kogel.Dapper.Extension/Expressions/ExpressionModifier.cs:
--------------------------------------------------------------------------------
1 | using System.Linq.Expressions;
2 |
3 | namespace Kogel.Dapper.Extension.Expressions
4 | {
5 | internal class ExpressionModifier : ExpressionVisitor
6 | {
7 | public ExpressionModifier(Expression newExpression, Expression oldExpression)
8 | {
9 | _newExpression = newExpression;
10 | _oldExpression = oldExpression;
11 | }
12 |
13 | private readonly Expression _newExpression;
14 | private readonly Expression _oldExpression;
15 |
16 | public Expression Replace(Expression node)
17 | {
18 | return Visit(node == _oldExpression ? _newExpression : node);
19 | }
20 |
21 | public static Expression Replace(Expression node, Expression oldExpression, Expression newExpression)
22 | {
23 | return new ExpressionModifier(newExpression, oldExpression).Replace(node);
24 | }
25 | }
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/Kogel.Repository/Interfaces/IUnitOfWork.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using System.Data;
7 |
8 | namespace Kogel.Repository.Interfaces
9 | {
10 | public interface IUnitOfWork : IDisposable
11 | {
12 | ///
13 | /// 数据库连接
14 | ///
15 | IDbConnection Connection { get; }
16 |
17 | ///
18 | /// 工作单元事务
19 | ///
20 | IDbTransaction Transaction { get; set; }
21 |
22 | ///
23 | /// 开启事务
24 | ///
25 | ///
26 | ///
27 | IUnitOfWork BeginTransaction(Action transactionMethod, IsolationLevel isolationLevel = IsolationLevel.ReadCommitted);
28 |
29 | ///
30 | /// 提交
31 | ///
32 | void Commit();
33 |
34 | ///
35 | /// 回滚
36 | ///
37 | void Rollback();
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/Kogel.Dapper.Extension/Core/SetQ/QuerySet.Select.cs:
--------------------------------------------------------------------------------
1 | using Kogel.Dapper.Extension.Core.Interfaces;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Data;
5 | using System.Linq;
6 | using System.Linq.Expressions;
7 | using System.Text;
8 | using System.Threading.Tasks;
9 |
10 | namespace Kogel.Dapper.Extension.Core.SetQ
11 | {
12 | public class QuerySet : QuerySet, IQuerySet
13 | {
14 | public QuerySet(IDbConnection conn, SqlProvider sqlProvider) : base(conn, sqlProvider)
15 | {
16 | }
17 |
18 | public QuerySet(IDbConnection conn, SqlProvider sqlProvider, IDbTransaction dbTransaction) : base(conn, sqlProvider, dbTransaction)
19 | {
20 | }
21 |
22 | public IQuery Select(Expression> select)
23 | {
24 | SqlProvider.Context.Set.SelectExpression = select;
25 | return this as IQuery;
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/Kogel.Dapper.Extension/Core/Interfaces/ICodeFirst.cs:
--------------------------------------------------------------------------------
1 | using System.Data;
2 | using Kogel.Dapper.Extension.Entites;
3 |
4 | namespace Kogel.Dapper.Extension.Core.Interfaces
5 | {
6 | ///
7 | /// 同步实体到数据库
8 | ///
9 | public interface ICodeFirst
10 | {
11 | ///
12 | /// 同步字段(生成sql)
13 | ///
14 | ///
15 | ///
16 | string SyncField(EntityObject typeEntity, EntityField field);
17 |
18 | ///
19 | /// 同步单个表结构
20 | ///
21 | ///
22 | void SyncTable(EntityObject typeEntity);
23 |
24 | ///
25 | /// 同步整体实体结构
26 | ///
27 | void SyncStructure();
28 |
29 | ///
30 | /// 转换字段类型
31 | ///
32 | /// 字段类型
33 | /// 长度
34 | ///
35 | string ConversionFieldType(SqlDbType sqlDbType, int length);
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/Kogel.Dapper.Extension/Entites/Navigation.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Linq.Expressions;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 |
8 | namespace Kogel.Dapper.Extension.Entites
9 | {
10 | ///
11 | /// 导航属性的关联解析实体
12 | ///
13 | public class Navigation
14 | {
15 | public Navigation()
16 | {
17 | //WhereExpressionList = new List();
18 | }
19 |
20 | ///
21 | /// 属性字段(当前定义的字段)
22 | ///
23 | public string AssoField { get; set; }
24 | ///
25 | /// 关联条件
26 | ///
27 | public string JoinWhere { get; set; }
28 | ///
29 | /// 连接表实体
30 | ///
31 | public Type JsonAssoTable { get; set; }
32 | ///
33 | /// 导航类型(0实体,1列表(集合))
34 | ///
35 | public NavigationEnum NavigationType { get; set; }
36 | }
37 |
38 | public enum NavigationEnum
39 | {
40 | Model = 0,
41 | List = 1
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/Kogel.Repository/Global.cs:
--------------------------------------------------------------------------------
1 | using Kogel.Repository.Entites;
2 | using System;
3 | using System.Collections.Concurrent;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace Kogel.Repository
10 | {
11 | ///
12 | /// 全局设置
13 | ///
14 | internal static class Global
15 | {
16 | ///
17 | /// 初始化
18 | ///
19 | static Global()
20 | {
21 | ConnectionPool = new ConcurrentBag();
22 | ProviderPool = new ConcurrentBag();
23 | }
24 |
25 | ///
26 | /// 总连接池 (所有连接都会注册到总连接池中,总连接池中不区分主从)
27 | ///
28 | internal static ConcurrentBag ConnectionPool { get; }
29 |
30 | ///
31 | /// 解析方池(总连接池中不区分主从)
32 | ///
33 | internal static ConcurrentBag ProviderPool { get; }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/Kogel.Dapper.Extension.Test/UnitTest/Oracle/Query.cs:
--------------------------------------------------------------------------------
1 | using Kogel.Dapper.Extension.Oracle;
2 | using Kogel.Dapper.Extension.Test.Model;
3 | using Oracle.ManagedDataAccess.Client;
4 | using Kogel.Dapper.Extension.Oracle.Extension;
5 |
6 | namespace Kogel.Dapper.Extension.Test.UnitTest.Oracle
7 | {
8 | public class Query
9 | {
10 |
11 | public void Test()
12 | {
13 |
14 | using (var conn = new OracleConnection("user id=adonis;password=adonis;data source=192.168.0.120:1521/helowin; Pooling=false;"))
15 | {
16 | //EntityCache.Register(new System.Type[] { typeof(FlowOrder), typeof(HeadOrder), typeof(WarehouseOrder) });
17 | //var codeFirst = new CodeFirst(conn);
18 | //codeFirst.SyncStructure();
19 |
20 | var flowOrders = conn.QuerySet()
21 | .Where(x => x.CustomerCode == "test")
22 | .Top(2)
23 | .ToList();
24 | }
25 |
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/Kogel.Dapper.Extension/Entites/DynamicTree.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Data;
4 | using System.Linq.Expressions;
5 | using System.Text;
6 |
7 | namespace Kogel.Dapper.Extension.Entites
8 | {
9 | public class DynamicTree
10 | {
11 | public DynamicTree()
12 | {
13 | Operators = ExpressionType.Equal;
14 | ValueType = DbType.String;
15 | }
16 | ///
17 | /// 对应字段的表(默认为空)
18 | ///
19 | public string Table { get; set; }
20 | ///
21 | /// 字段
22 | ///
23 | public string Field { get; set; }
24 | ///
25 | /// 判断方式(13 等于,6 模糊查询,16 大于等于,21 小于等于)
26 | ///
27 | public ExpressionType Operators { get; set; }
28 | ///
29 | /// 判断的值
30 | ///
31 | public string Value { get; set; }
32 | ///
33 | /// 值类型(6 DateTime,11 Int32,16 String)
34 | ///
35 | public DbType ValueType { get; set; }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/Kogel.Dapper.Extension.Test/Dto/AppConfigDto1.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace Kogel.Dapper.Extension.Test.Dto
8 | {
9 | public class AppConfigDto1
10 | {
11 | ///
12 | ///
13 | ///
14 | public int Id { get; set; }
15 | ///
16 | /// 编码(唯一标识)
17 | ///
18 | public string Code { get; set; }
19 | ///
20 | /// 父级id
21 | ///
22 | public int ParentId { get; set; }
23 | ///
24 | /// 标题
25 | ///
26 | public string Title { get; set; }
27 | ///
28 | /// 商场id
29 | ///
30 | public string MarketId { get; set; }
31 | ///
32 | /// 描述
33 | ///
34 | public string Description { get; set; }
35 | ///
36 | /// 父级名称
37 | ///
38 | public string ParentName { get; set; }
39 | ///
40 | ///
41 | ///
42 | public bool IsDelete { get; set; }
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/Kogel.Repository/Entites/ConnectionPool.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Data;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 |
8 | namespace Kogel.Repository.Entites
9 | {
10 | ///
11 | ///
12 | ///
13 | public class ConnectionPool
14 | {
15 | ///
16 | ///
17 | ///
18 | public Func FuncConnection { get; set; }
19 |
20 | ///
21 | /// 连接字符串(内部判断使用)
22 | ///
23 | internal string ConnectionString { get; set; }
24 |
25 | ///
26 | /// 数据库名称(自定义标识)
27 | ///
28 | public string DbName { get; set; }
29 |
30 | ///
31 | /// 数据库名称(实际名称)
32 | ///
33 | public string Database { get; set; }
34 |
35 | ///
36 | /// 数据源地址
37 | ///
38 | public string DataSource { get; set; }
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/Kogel.Dapper.Extension/Dapper/SqlMapper.LiteralToken.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 |
3 | namespace Kogel.Dapper.Extension
4 | {
5 | public static partial class SqlMapper
6 | {
7 | ///
8 | /// Represents a placeholder for a value that should be replaced as a literal value in the resulting sql
9 | ///
10 | internal struct LiteralToken
11 | {
12 | ///
13 | /// The text in the original command that should be replaced
14 | ///
15 | public string Token { get; }
16 |
17 | ///
18 | /// The name of the member referred to by the token
19 | ///
20 | public string Member { get; }
21 |
22 | internal LiteralToken(string token, string member)
23 | {
24 | Token = token;
25 | Member = member;
26 | }
27 |
28 | internal static readonly IList None = new LiteralToken[0];
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/Kogel.Dapper.Extension/Dapper/DynamicParameters.ParamInfo.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Data;
3 |
4 | namespace Kogel.Dapper.Extension
5 | {
6 | public partial class DynamicParameters
7 | {
8 | private sealed class ParamInfo
9 | {
10 | public string Name { get; set; }
11 | public object Value { get; set; }
12 | public ParameterDirection ParameterDirection { get; set; }
13 | public DbType? DbType { get; set; }
14 | public int? Size { get; set; }
15 | public IDbDataParameter AttachedParam { get; set; }
16 | internal Action