{"action":"created","issue":{"url":"https://api.github.com/repos/thangchung/awesome-dotnet-core/issues/346","repository_url":"https://api.github.com/repos/thangchung/awesome-dotnet-core","labels_url":"https://api.github.com/repos/thangchung/awesome-dotnet-core/issues/346/labels{/name}","comments_url":"https://api.github.com/repos/thangchung/awesome-dotnet-core/issues/346/comments","events_url":"https://api.github.com/repos/thangchung/awesome-dotnet-core/issues/346/events","html_url":"https://github.com/thangchung/awesome-dotnet-core/pull/346","id":345769412,"node_id":"MDExOlB1bGxSZXF1ZXN0MjA0ODEzMTM0","number":346,"title":"add ORM:SmartSql https://github.com/Ahoo-Wang/SmartSql","user":{"login":"Ahoo-Wang","id":4384159,"node_id":"MDQ6VXNlcjQzODQxNTk=","avatar_url":"https://avatars2.githubusercontent.com/u/4384159?v=4","gravatar_id":"","url":"https://api.github.com/users/Ahoo-Wang","html_url":"https://github.com/Ahoo-Wang","followers_url":"https://api.github.com/users/Ahoo-Wang/followers","following_url":"https://api.github.com/users/Ahoo-Wang/following{/other_user}","gists_url":"https://api.github.com/users/Ahoo-Wang/gists{/gist_id}","starred_url":"https://api.github.com/users/Ahoo-Wang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Ahoo-Wang/subscriptions","organizations_url":"https://api.github.com/users/Ahoo-Wang/orgs","repos_url":"https://api.github.com/users/Ahoo-Wang/repos","events_url":"https://api.github.com/users/Ahoo-Wang/events{/privacy}","received_events_url":"https://api.github.com/users/Ahoo-Wang/received_events","type":"User","site_admin":false},"labels":[{"id":976155768,"node_id":"MDU6TGFiZWw5NzYxNTU3Njg=","url":"https://api.github.com/repos/thangchung/awesome-dotnet-core/labels/In%20Preview","name":"In Preview","color":"231b7c","default":false}],"state":"open","locked":false,"assignee":{"login":"thangchung","id":422341,"node_id":"MDQ6VXNlcjQyMjM0MQ==","avatar_url":"https://avatars1.githubusercontent.com/u/422341?v=4","gravatar_id":"","url":"https://api.github.com/users/thangchung","html_url":"https://github.com/thangchung","followers_url":"https://api.github.com/users/thangchung/followers","following_url":"https://api.github.com/users/thangchung/following{/other_user}","gists_url":"https://api.github.com/users/thangchung/gists{/gist_id}","starred_url":"https://api.github.com/users/thangchung/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thangchung/subscriptions","organizations_url":"https://api.github.com/users/thangchung/orgs","repos_url":"https://api.github.com/users/thangchung/repos","events_url":"https://api.github.com/users/thangchung/events{/privacy}","received_events_url":"https://api.github.com/users/thangchung/received_events","type":"User","site_admin":false},"assignees":[{"login":"thangchung","id":422341,"node_id":"MDQ6VXNlcjQyMjM0MQ==","avatar_url":"https://avatars1.githubusercontent.com/u/422341?v=4","gravatar_id":"","url":"https://api.github.com/users/thangchung","html_url":"https://github.com/thangchung","followers_url":"https://api.github.com/users/thangchung/followers","following_url":"https://api.github.com/users/thangchung/following{/other_user}","gists_url":"https://api.github.com/users/thangchung/gists{/gist_id}","starred_url":"https://api.github.com/users/thangchung/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thangchung/subscriptions","organizations_url":"https://api.github.com/users/thangchung/orgs","repos_url":"https://api.github.com/users/thangchung/repos","events_url":"https://api.github.com/users/thangchung/events{/privacy}","received_events_url":"https://api.github.com/users/thangchung/received_events","type":"User","site_admin":false},{"login":"ngohungphuc","id":13591213,"node_id":"MDQ6VXNlcjEzNTkxMjEz","avatar_url":"https://avatars3.githubusercontent.com/u/13591213?v=4","gravatar_id":"","url":"https://api.github.com/users/ngohungphuc","html_url":"https://github.com/ngohungphuc","followers_url":"https://api.github.com/users/ngohungphuc/followers","following_url":"https://api.github.com/users/ngohungphuc/following{/other_user}","gists_url":"https://api.github.com/users/ngohungphuc/gists{/gist_id}","starred_url":"https://api.github.com/users/ngohungphuc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ngohungphuc/subscriptions","organizations_url":"https://api.github.com/users/ngohungphuc/orgs","repos_url":"https://api.github.com/users/ngohungphuc/repos","events_url":"https://api.github.com/users/ngohungphuc/events{/privacy}","received_events_url":"https://api.github.com/users/ngohungphuc/received_events","type":"User","site_admin":false}],"milestone":null,"comments":5,"created_at":"2018-07-30T13:57:14Z","updated_at":"2018-10-06T16:39:27Z","closed_at":null,"author_association":"NONE","pull_request":{"url":"https://api.github.com/repos/thangchung/awesome-dotnet-core/pulls/346","html_url":"https://github.com/thangchung/awesome-dotnet-core/pull/346","diff_url":"https://github.com/thangchung/awesome-dotnet-core/pull/346.diff","patch_url":"https://github.com/thangchung/awesome-dotnet-core/pull/346.patch"},"body":"<p align=\"center\">\r\n  <a href=\"https://doc.smartsql.net/\" target=\"_blank\"><img width=\"100\"src=\"https://raw.githubusercontent.com/Ahoo-Wang/SmartSql/master/SmartSql.png\"></a>\r\n</p>\r\n\r\n# 简介\r\n\r\n[![Join the chat at https://gitter.im/SmartSql-DotNet/Lobby](https://badges.gitter.im/SmartSql-DotNet/Lobby.svg)](https://gitter.im/SmartSql-DotNet/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)\r\n\r\n>[SmartSql-Starter](https://github.com/Ahoo-Wang/SmartSql-Starter)\r\n\r\n## Nuget Packages\r\n\r\n| Package | NuGet Stable |  Downloads |\r\n| ------- | -------- | ------- |\r\n| [SmartSql](https://www.nuget.org/packages/SmartSql/) | [![SmartSql](https://img.shields.io/nuget/v/SmartSql.svg)](https://www.nuget.org/packages/SmartSql/)  | [![SmartSql](https://img.shields.io/nuget/dt/SmartSql.svg)](https://www.nuget.org/packages/SmartSql/) |\r\n| [SmartSql.TypeHandler](https://www.nuget.org/packages/SmartSql.TypeHandler/) | [![SmartSql.TypeHandler](https://img.shields.io/nuget/v/SmartSql.TypeHandler.svg)](https://www.nuget.org/packages/SmartSql.TypeHandler/)  | [![SmartSql.TypeHandler](https://img.shields.io/nuget/dt/SmartSql.TypeHandler.svg)](https://www.nuget.org/packages/SmartSql.TypeHandler/) |\r\n| [SmartSql.DyRepository](https://www.nuget.org/packages/SmartSql.DyRepository/) | [![SmartSql.DyRepository](https://img.shields.io/nuget/v/SmartSql.DyRepository.svg)](https://www.nuget.org/packages/SmartSql.DyRepository/)  | [![SmartSql.DyRepository](https://img.shields.io/nuget/dt/SmartSql.DyRepository.svg)](https://www.nuget.org/packages/SmartSql.DyRepository/) |\r\n| [SmartSql.DIExtension](https://www.nuget.org/packages/SmartSql.DIExtension/) | [![SmartSql.DIExtension](https://img.shields.io/nuget/v/SmartSql.DIExtension.svg)](https://www.nuget.org/packages/SmartSql.DIExtension/)  | [![SmartSql.DIExtension](https://img.shields.io/nuget/dt/SmartSql.DIExtension.svg)](https://www.nuget.org/packages/SmartSql.DIExtension/) |\r\n| [SmartSql.Cache.Redis](https://www.nuget.org/packages/SmartSql.Cache.Redis/) | [![SmartSql.Cache.Redis](https://img.shields.io/nuget/v/SmartSql.Cache.Redis.svg)](https://www.nuget.org/packages/SmartSql.Cache.Redis/)  | [![SmartSql.Cache.Redis](https://img.shields.io/nuget/dt/SmartSql.Cache.Redis.svg)](https://www.nuget.org/packages/SmartSql.Cache.Redis/) |\r\n| [SmartSql.ZooKeeperConfig](https://www.nuget.org/packages/SmartSql.ZooKeeperConfig/) | [![SmartSql.ZooKeeperConfig](https://img.shields.io/nuget/v/SmartSql.ZooKeeperConfig.svg)](https://www.nuget.org/packages/SmartSql.ZooKeeperConfig/)  | [![SmartSql.ZooKeeperConfig](https://img.shields.io/nuget/dt/SmartSql.ZooKeeperConfig.svg)](https://www.nuget.org/packages/SmartSql.ZooKeeperConfig/) |\r\n\r\n## 0. Why\r\n\r\n- 拥抱 跨平台 DotNet Core，是时候了。\r\n- 高性能、高生产力，超轻量级的ORM。**107kb**\r\n\r\n---\r\n\r\n## 1. So SmartSql\r\n\r\n- TargetFrameworks: .NETFramework 4.6 & .NETStandard 2.0\r\n- SmartSql = MyBatis + Cache(Memory | Redis) + ZooKeeper + R/W Splitting + ......\r\n\r\n---\r\n\r\n## 2. 主要特性\r\n\r\n- 1 ORM\r\n  - 1.1 Sync\r\n  - 1.2 Async\r\n- 2 XmlConfig & XmlStatement -> Sql\r\n  - 2.1 SmartSqlMapConfig & SmartSqlMap (是的，你猜对了，和MyBatis一样，通过XML配置分离SQL。)\r\n  - 2.2 Config Hot Update ->ConfigWatcher & Reload (配置文件热更新：当你需要修改Sql的时候，直接修改SqlMap配置文件，保存即可。)\r\n- 3 读写分离\r\n  - 3.1 读写分离\r\n  - 3.2 多读库 权重筛选 （配置多读库，根据读库权重选举读库）\r\n- 4 日志\r\n  - 4.1 基于 Microsoft.Extensions.Logging.Abstractions  (当你需要跟踪调试的时候一切都是那么一目了然)\r\n- 5 Dynamic Repository\r\n  - 5.1 SmartSql.DyRepository  （解放你的双手，你来定义仓储接口，我来实现数据库访问）\r\n- 6 查询缓存  （热数据缓存，一个配置轻松搞定）\r\n  - 6.1 SmartSql.Cache.Memory\r\n    - 6.1.1 Fifo\r\n    - 6.1.2 Lru\r\n  - 6.2 SmartSql.Cache.Redis\r\n  - 6.3 缓存事务一致性\r\n- 7 分布式配置插件\r\n  - 7.1 IConfigLoader (配置文件加载器)\r\n  - 7.2 LocalFileConfigLoader  (本地文件配置加载器)\r\n    - 7.2.1 Load SmartSqlMapSource Xml\r\n    - 7.3.1 Load SmartSqlMapSource Directory\r\n  - 7.3 SmartSql.ZooKeeperConfig (ZooKeeper 分布式配置文件加载器)\r\n\r\n---\r\n\r\n## 3. 性能评测\r\n\r\n``` ini\r\n\r\nBenchmarkDotNet=v0.10.14, OS=Windows 10.0.17134\r\nIntel Core i7-6700K CPU 4.00GHz (Skylake), 1 CPU, 8 logical and 4 physical cores\r\n.NET Core SDK=2.1.201\r\n  [Host]     : .NET Core 2.0.7 (CoreCLR 4.6.26328.01, CoreFX 4.6.26403.03), 64bit RyuJIT\r\n  DefaultJob : .NET Core 2.0.7 (CoreCLR 4.6.26328.01, CoreFX 4.6.26403.03), 64bit RyuJIT\r\n\r\n\r\n```\r\n|            ORM |                     Type |                  Method |        Return |      Mean |     Error |    StdDev | Rank |     Gen 0 |     Gen 1 |     Gen 2 | Allocated |\r\n|--------------- |------------------------- |------------------------ |-------------- |----------:|----------:|----------:|-----:|----------:|----------:|----------:|----------:|\r\n|         Native |         NativeBenchmarks |   Query_GetValue_DbNull | IEnumerable`1 |  78.39 ms | 0.8935 ms | 0.7921 ms |    1 | 3000.0000 | 1125.0000 |  500.0000 |  15.97 MB |\r\n|       SmartSql |       SmartSqlBenchmarks |                   Query | IEnumerable`1 |  78.46 ms | 0.2402 ms | 0.1875 ms |    1 | 2312.5000 | 1000.0000 |  312.5000 |  12.92 MB |\r\n| SmartSqlDapper | SmartSqlDapperBenchmarks |                   Query | IEnumerable`1 |  78.65 ms | 1.2094 ms | 1.1312 ms |    1 | 3687.5000 | 1437.5000 |  687.5000 |  19.03 MB |\r\n|         Native |         NativeBenchmarks | Query_IsDBNull_GetValue | IEnumerable`1 |  78.84 ms | 0.8984 ms | 0.7502 ms |    1 | 2312.5000 | 1000.0000 |  312.5000 |  12.92 MB |\r\n|         Dapper |         DapperBenchmarks |                   Query | IEnumerable`1 |  79.00 ms | 1.0949 ms | 0.9706 ms |    1 | 3312.5000 | 1312.5000 |  625.0000 |  17.19 MB |\r\n|             EF |             EFBenchmarks |                   Query | IEnumerable`1 |  79.44 ms | 1.6880 ms | 1.5789 ms |    1 | 6250.0000 |         - |         - |  26.05 MB |\r\n|       SqlSugar |       SqlSugarBenchmarks |                   Query | IEnumerable`1 |  81.09 ms | 0.8718 ms | 0.7728 ms |    2 | 2187.5000 |  875.0000 |  250.0000 |  12.64 MB |\r\n|          Chloe |          ChloeBenchmarks |                   Query | IEnumerable`1 |  83.86 ms | 1.2714 ms | 1.1893 ms |    3 | 2250.0000 |  937.5000 |  312.5000 |  12.62 MB |\r\n|             EF |             EFBenchmarks |                SqlQuery | IEnumerable`1 |  89.11 ms | 0.7562 ms | 0.6314 ms |    4 | 8187.5000 |  125.0000 |         - |  33.68 MB |\r\n|             EF |             EFBenchmarks |        Query_NoTracking | IEnumerable`1 |  93.13 ms | 0.8458 ms | 0.7912 ms |    5 | 5875.0000 | 2250.0000 | 1062.5000 |  29.71 MB |\r\n|             EF |             EFBenchmarks |     SqlQuery_NoTracking | IEnumerable`1 | 106.89 ms | 1.0998 ms | 1.0288 ms |    6 | 7437.5000 | 2875.0000 | 1312.5000 |  37.34 MB |\r\n\r\n---\r\n\r\n## 4. 安装 (NuGet)\r\n\r\n``` csharp\r\nInstall-Package SmartSql\r\n```\r\n\r\n## 5. 常规代码\r\n\r\n### 查询\r\n\r\n``` csharp\r\n            ISmartSqlMapper SqlMapper = MapperContainer.Instance.GetSqlMapper();\r\n            SqlMapper.Query<T_Test>(new RequestContext\r\n            {\r\n                Scope = \"T_Test\",\r\n                SqlId = \"GetList\",\r\n                Request = new { Ids = new long[] { 1, 2, 3, 4 } }\r\n            });\r\n```\r\n\r\n### 事务\r\n\r\n``` csharp\r\n            try\r\n            {\r\n                ISmartSqlMapper SqlMapper = MapperContainer.Instance.GetSqlMapper();\r\n                SqlMapper.BeginTransaction();\r\n                //BizCode\r\n                SqlMapper.CommitTransaction();\r\n            }\r\n            catch (Exception ex)\r\n            {\r\n                SqlMapper.RollbackTransaction();\r\n                throw ex;\r\n            }\r\n```\r\n\r\n## 6. 最佳实践\r\n\r\n### 6.1 安装 SmartSql.DIExtension\r\n\r\n``` chsarp\r\nInstall-Package SmartSql.DIExtension\r\n```\r\n\r\n### 6.2 注入依赖\r\n\r\n``` csharp\r\n services.AddSmartSql();\r\n services.AddRepositoryFactory();\r\n services.AddRepositoryFromAssembly((options) =>\r\n {\r\n    options.AssemblyString = \"SmartSql.Starter.Repository\";\r\n });\r\n```\r\n\r\n### 6.3 定义仓储接口\r\n\r\n``` csharp\r\n    /// <summary>\r\n    /// 属性可选： [SqlMap(Scope = \"User\")] ,不设置 则默认 Scope 模板：I{Scope}Repository\r\n    /// 可传入自定义模板\r\n    /// RepositoryBuilder builder=new RepositoryBuilder(\"I{Scope}Repository\");\r\n    /// </summary>\r\n    public interface IUserRepository\r\n    {\r\n        /// <summary>\r\n        /// 属性可选 [Statement(Execute = ExecuteBehavior.Auto,Id = \"Query\")]\r\n        /// 默认 Execute：Auto ，自动判断 执行类型\r\n        /// 默认 Id : 方法名\r\n        /// </summary>\r\n        /// <param name=\"reqParams\"></param>\r\n        /// <returns></returns>\r\n        IEnumerable<User> Query(object reqParams);\r\n        int GetRecord(object reqParams);\r\n        User GetById([Param(\"Id\")]long id);\r\n        long Insert(User entity);\r\n        int Update(User entity);\r\n        int Delete(User enttiy);\r\n        [Statement(Sql = \"Select Top(@taken) T.* From T_User T With(NoLock);\")]\r\n        Task<IEnumerable<User>> QueryBySqlAsync(int taken);\r\n        bool IsExist(object reqParams);\r\n    }\r\n```\r\n\r\n### 6.4 尽情享用\r\n\r\n``` csharp\r\n    public class UserService\r\n    {\r\n        private readonly ITransaction _transaction;\r\n        private readonly IUserRepository _userRepository;\r\n\r\n        public UserService(\r\n             ITransaction transaction\r\n            , IUserRepository userRepository)\r\n        {\r\n            _transaction = transaction;\r\n            _userRepository = userRepository;\r\n        }\r\n\r\n        public long Add(AddRequest request)\r\n        {\r\n            int existsNum = _userRepository.Exists(new { request.UserName });\r\n            if (existsNum > 0)\r\n            {\r\n                throw new ArgumentException($\"{nameof(request.UserName)} has already existed!\");\r\n            }\r\n            return _userRepository.Insert(new Entitiy.User\r\n            {\r\n                UserName = request.UserName,\r\n                Password = request.Password,\r\n                Status = Entitiy.UserStatus.Ok,\r\n                CreationTime = DateTime.Now,\r\n            });\r\n        }\r\n\r\n        public void UseTransaction()\r\n        {\r\n            try\r\n            {\r\n                _transaction.BeginTransaction();\r\n                //Biz();\r\n                _transaction.CommitTransaction();\r\n            }\r\n            catch (Exception ex)\r\n            {\r\n                _transaction.RollbackTransaction();\r\n                throw ex;\r\n            }\r\n        }\r\n    }\r\n```\r\n\r\n## 7. 文档地址\r\n\r\n- [在线阅读地址](https://doc.smartsql.net/)\r\n- [PDF](https://www.gitbook.com/download/pdf/book/ahoo-wang/smartsql-doc-cn)\r\n- [Mobi](https://www.gitbook.com/download/mobi/book/ahoo-wang/smartsql-doc-cn)\r\n- [ePub](https://www.gitbook.com/download/epub/book/ahoo-wang/smartsql-doc-cn)\r\n\r\n## 8. 技术交流\r\n\r\n点击链接加入QQ群【SmartSql 官方交流群】：[604762592](https://jq.qq.com/?_wv=1027&k=5Sy8Ahw)"},"comment":{"url":"https://api.github.com/repos/thangchung/awesome-dotnet-core/issues/comments/427588044","html_url":"https://github.com/thangchung/awesome-dotnet-core/pull/346#issuecomment-427588044","issue_url":"https://api.github.com/repos/thangchung/awesome-dotnet-core/issues/346","id":427588044,"node_id":"MDEyOklzc3VlQ29tbWVudDQyNzU4ODA0NA==","user":{"login":"ngohungphuc","id":13591213,"node_id":"MDQ6VXNlcjEzNTkxMjEz","avatar_url":"https://avatars3.githubusercontent.com/u/13591213?v=4","gravatar_id":"","url":"https://api.github.com/users/ngohungphuc","html_url":"https://github.com/ngohungphuc","followers_url":"https://api.github.com/users/ngohungphuc/followers","following_url":"https://api.github.com/users/ngohungphuc/following{/other_user}","gists_url":"https://api.github.com/users/ngohungphuc/gists{/gist_id}","starred_url":"https://api.github.com/users/ngohungphuc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ngohungphuc/subscriptions","organizations_url":"https://api.github.com/users/ngohungphuc/orgs","repos_url":"https://api.github.com/users/ngohungphuc/repos","events_url":"https://api.github.com/users/ngohungphuc/events{/privacy}","received_events_url":"https://api.github.com/users/ngohungphuc/received_events","type":"User","site_admin":false},"created_at":"2018-10-06T16:39:27Z","updated_at":"2018-10-06T16:39:27Z","author_association":"COLLABORATOR","body":"Please resolve conflict then I will merge this pr\r\n"}}
{"actor":{"display_login":"ngohungphuc"}}