├── .gitignore ├── Benchmarks ├── App.config ├── Benchmarks.csproj ├── Employee.cs ├── Inserts.cs ├── Program.cs ├── Properties │ └── AssemblyInfo.cs ├── Simple.cs └── packages.config ├── ConsoleTests ├── App.config ├── ArrayEqualityComparer.cs ├── Bad │ ├── Bad1.cs │ ├── Bad2.cs │ ├── Bad3.cs │ ├── Bad4.cs │ └── Bad5.cs ├── ConsoleTests.csproj ├── ConsoleTests.csproj.user ├── Good │ ├── Dto10.cs │ ├── Dto11.cs │ ├── Dto12.cs │ ├── Dto13.cs │ ├── Dto14.cs │ ├── Dto15.cs │ ├── IDto.cs │ ├── IDtoKey.cs │ ├── IFilter.cs │ ├── Test3.cs │ ├── Test3filter.cs │ ├── Test7.cs │ ├── Test7filter.cs │ ├── Test8.cs │ ├── Test8filter.cs │ ├── Test9.cs │ ├── Test9filter.cs │ ├── TestDTO.cs │ ├── TestDTO2.cs │ ├── TestDTO2filter.cs │ ├── TestDTO4.cs │ ├── TestDTO4filter.cs │ ├── TestDTO5.cs │ ├── TestDTO5filter.cs │ ├── TestDTO6.cs │ ├── TestDTO6filter.cs │ └── TestDTOfilter.cs ├── Program.cs ├── Properties │ └── AssemblyInfo.cs └── packages.config ├── DapperExtraCRUD.Cache.Example ├── App.config ├── DapperExtraCRUD.Cache.Example.csproj ├── Program.cs ├── Properties │ └── AssemblyInfo.cs └── packages.config ├── DapperExtraCRUD.Cache ├── CacheItem.cs ├── DapperExtraCRUD.Cache.csproj ├── DbCache.cs ├── DbCacheTable.cs ├── DbCacheTransaction.cs ├── ICacheStorage.cs ├── ICacheTable.cs ├── Internal │ ├── CacheAutoStorage.cs │ └── CacheTransactionStorage.cs └── README.md ├── DapperExtraCRUD.Example ├── App.config ├── BulkOptionsAdapter.cs ├── CollateAdapter.cs ├── DapperExtraCRUD.Example.csproj ├── DapperExtraCRUD.Example.csproj.user ├── Program.cs ├── Properties │ └── AssemblyInfo.cs ├── User.cs ├── UserPermissions.cs └── packages.config ├── DapperExtraCRUD.sln ├── DapperExtraCRUD ├── DapperExtraCRUD.csproj ├── DapperExtraCRUD.csproj.user ├── DapperExtraExtensions.cs ├── DapperExtraWhereExtensions.cs ├── Extra │ ├── Adapters │ │ ├── MySqlAdapter.cs │ │ ├── OracleAdapter.cs │ │ ├── PostgreSqlAdapter.cs │ │ ├── SqlAdapterImpl.cs │ │ ├── SqlLiteAdapter.cs │ │ └── SqlServerAdapter.cs │ ├── Annotations │ │ ├── AutoSyncAttribute.cs │ │ ├── ColumnAttribute.cs │ │ ├── IDefaultAttribute.cs │ │ ├── IgnoreDeleteAttribute.cs │ │ ├── IgnoreInsertAttribute.cs │ │ ├── IgnoreSelectAttribute.cs │ │ ├── IgnoreUpdateAttribute.cs │ │ ├── KeyAttribute.cs │ │ ├── MatchDeleteAttribute.cs │ │ ├── MatchUpdateAttribute.cs │ │ ├── NotMappedAttribute.cs │ │ └── TableAttribute.cs │ ├── Delegates.cs │ ├── ExtraCrud.cs │ ├── ExtraUtil.cs │ ├── ISqlAdapter.cs │ ├── ISqlBuilder.cs │ ├── ISqlQueries.cs │ ├── Internal │ │ ├── Constants.cs │ │ ├── SqlBuilderHelper.cs │ │ ├── SqlQueries.cs │ │ └── TableEqualityComparer.cs │ ├── SqlAdapter.cs │ ├── SqlBuilder.cs │ ├── SqlColumn.cs │ ├── SqlColumnAttributes.cs │ ├── SqlDialect.cs │ ├── SqlTableAttributes.cs │ ├── SqlTypeInfo.cs │ ├── Utilities │ │ ├── AutoAccessObject.cs │ │ ├── ConnectedEnumerable.cs │ │ ├── DataAccessObject.cs │ │ ├── IAccessObject.cs │ │ ├── IAccessObjectAsync.cs │ │ ├── IAccessObjectSync.cs │ │ ├── IDataAccessObject.cs │ │ ├── ITransactionAccessObjectAsync.cs │ │ ├── ITransactionAccessObjectSync.cs │ │ └── WhereConditionGenerator.cs │ └── WhereConditionData.cs └── key.snk ├── Images ├── DapperExtraCRUD-200x200.png ├── DapperExtraCRUD-200x200.xcf ├── DapperExtraCRUD-500x500.png ├── DapperExtraCRUD-500x500.xcf └── DapperExtraCRUD.xcf └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | /.vs 2 | /*/bin 3 | /*/obj 4 | /packages 5 | /TestResults 6 | /*/nuget/* 7 | -------------------------------------------------------------------------------- /Benchmarks/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | -------------------------------------------------------------------------------- /Benchmarks/Employee.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Dapper.Extra.Annotations; 3 | 4 | namespace Benchmarks 5 | { 6 | public enum Permission 7 | { 8 | None = 0, 9 | Basic, 10 | Admin, 11 | SuperAdmin, 12 | Count, 13 | } 14 | 15 | public enum PayType 16 | { 17 | None = 0, 18 | Contractor, 19 | Salary, 20 | Hourly, 21 | Count, 22 | } 23 | 24 | [Table("Employees")] 25 | public class Employee 26 | { 27 | [Key] 28 | public int EmployeeID { get; set; } 29 | public string FirstName { get; set; } 30 | public string LastName { get; set; } 31 | public Permission PermissionID { get; set; } 32 | public DateTime? Birthday { get; set; } 33 | public DateTime HireDate { get; set; } 34 | public string Division { get; set; } 35 | public string Department { get; set; } 36 | public string Title { get; set; } 37 | public int ManagerID { get; set; } 38 | public string Email { get; set; } 39 | public string Username { get; set; } 40 | public decimal Salary { get; set; } 41 | public string Status { get; set; } 42 | public string FormerLastName { get; set; } 43 | public string Nickname { get; set; } 44 | public double Weight { get; set; } 45 | public double Height { get; set; } 46 | public Guid GlobalID { get; set; } 47 | public DateTime LastLogin { get; set; } 48 | public int FailedLoginAttempts { get; set; } 49 | public char Sex { get; set; } 50 | public PayType PayType { get; set; } 51 | public decimal PtoHours { get; set; } 52 | 53 | public static Employee Create(Random random) 54 | { 55 | string firstName = random.Next().ToString(); 56 | string lastName = random.Next().ToString(); 57 | char sex = random.Next() % 100 > 60 ? 'M' : (random.Next() > 30 ? 'F' : ' '); 58 | string division = random.Next().ToString(); 59 | Employee emp = new Employee() { 60 | FirstName = firstName, 61 | LastName = lastName, 62 | PermissionID = (Permission)(random.Next() % (int)Permission.Count), 63 | Birthday = random.Next() % 5 == 0 ? null : (DateTime?)new DateTime(1960, 1, 1).AddDays(random.Next() % (45 * 365)).AddTicks(random.Next() % TimeSpan.TicksPerDay), 64 | HireDate = DateTime.Today.AddDays(0 - random.Next() % (365 * 15)), 65 | Division = division, 66 | Department = random.Next().ToString(), 67 | Title = random.Next().ToString(), 68 | ManagerID = 1, 69 | Email = firstName + "." + lastName + "@" + division + ".com", 70 | Username = firstName[0] + lastName, 71 | Salary = (40000 + random.Next() % 210000) + (random.Next() % 100 / 100m), 72 | Status = random.Next().ToString(), 73 | Sex = sex, 74 | FormerLastName = (random.Next() % 100 > 40 && sex == 'F') ? random.Next().ToString() : null, 75 | Nickname = random.Next() % 100 > 25 ? null : firstName.Substring(0, firstName.Length / 2), 76 | Weight = random.NextDouble() * 200 + 120, 77 | Height = random.NextDouble() * 2.7 + 5.3, 78 | GlobalID = Guid.NewGuid(), 79 | LastLogin = random.Next() % 100 <= 5 ? new DateTime(1753, 1, 1) : DateTime.Now.AddDays(random.NextDouble() * 8), 80 | FailedLoginAttempts = random.Next() % 100 > 50 ? random.Next() % 3 : 0, 81 | PayType = (PayType)(random.Next() % (int)PayType.Count), 82 | PtoHours = (decimal)random.NextDouble() * 250, 83 | }; 84 | return emp; 85 | } 86 | 87 | public static string CreateTableSql() 88 | { 89 | return @" 90 | CREATE TABLE [dbo].[Employees]( 91 | [EmployeeID] [int] IDENTITY(1,1) NOT NULL, 92 | [FirstName] [varchar](100) NOT NULL, 93 | [LastName] [varchar](100) NOT NULL, 94 | [FormerLastName] [varchar](150) NULL, 95 | [PermissionID] [int] NOT NULL, 96 | [Nickname] [varchar](150) NULL, 97 | [Birthday] [datetime2](7) NULL, 98 | [HireDate] [date] NOT NULL, 99 | [Email] [varchar](280) NOT NULL, 100 | [Title] [varchar](150) NULL, 101 | [Division] [varchar](150) NULL, 102 | [Department] [varchar](150) NULL, 103 | [ManagerID] [int] NOT NULL, 104 | [Username] [varchar](280) NOT NULL, 105 | [Salary] [decimal](18, 2) NOT NULL, 106 | [Status] [varchar](100) NOT NULL, 107 | [Weight] [decimal](9, 2) NULL, 108 | [Height] [decimal](9, 2) NULL, 109 | [GlobalID] [uniqueidentifier] NOT NULL, 110 | [LastLogin] [datetime2](7) NULL, 111 | [FailedLoginAttempts] [int] NOT NULL, 112 | [Sex] [char](1) NOT NULL, 113 | [PayType] [int] NOT NULL, 114 | [PtoHours] [decimal](9, 2) NOT NULL, 115 | CONSTRAINT [PK_Employees] PRIMARY KEY CLUSTERED 116 | ( 117 | [EmployeeID] ASC 118 | )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] 119 | ) ON [PRIMARY]"; 120 | } 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /Benchmarks/Program.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Released under MIT License 3 | // License: https://opensource.org/licenses/MIT 4 | // Home page: https://github.com/ffhighwind/DapperExtraCRUD 5 | 6 | // Copyright(c) 2018 Wesley Hamilton 7 | 8 | // Permission is hereby granted, free of charge, to any person obtaining a copy 9 | // of this software and associated documentation files (the "Software"), to deal 10 | // in the Software without restriction, including without limitation the rights 11 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the Software is 13 | // furnished to do so, subject to the following conditions: 14 | 15 | // The above copyright notice and this permission notice shall be included in all 16 | // copies or substantial portions of the Software. 17 | 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | // SOFTWARE. 25 | #endregion 26 | 27 | using BenchmarkDotNet.Attributes; 28 | using BenchmarkDotNet.Diagnosers; 29 | using BenchmarkDotNet.Running; 30 | 31 | namespace Benchmarks 32 | { 33 | [MemoryDiagnoser] 34 | public class Program 35 | { 36 | public static void Main() 37 | { 38 | // Produces benchmark data in bin\Release\BenchmarkDotNet.Artifacts\results 39 | _ = BenchmarkRunner.Run(); 40 | } 41 | } 42 | } -------------------------------------------------------------------------------- /Benchmarks/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("Benchmarks")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("Benchmarks")] 13 | [assembly: AssemblyCopyright("Copyright © 2019")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("5d35001d-5c45-4035-9484-8cd3d2edaaf8")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /Benchmarks/Simple.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Dapper.Extra.Annotations; 3 | 4 | namespace Benchmarks 5 | { 6 | public class Simple 7 | { 8 | [Key] 9 | public int ID { get; set; } 10 | public string Name { get; set; } 11 | 12 | public static Simple Create(Random random) 13 | { 14 | Simple simple = new Simple() { 15 | Name = random.Next().ToString() 16 | }; 17 | return simple; 18 | } 19 | 20 | public static string CreateTableSql() 21 | { 22 | return @" 23 | CREATE TABLE [dbo].[Simple]( 24 | [ID] [int] IDENTITY(1,1) NOT NULL, 25 | [Name] [varchar](150) NOT NULL, 26 | CONSTRAINT [PK_Simple] PRIMARY KEY CLUSTERED 27 | ( 28 | [ID] ASC 29 | )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] 30 | ) ON [PRIMARY]"; 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Benchmarks/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /ConsoleTests/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | -------------------------------------------------------------------------------- /ConsoleTests/ArrayEqualityComparer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Dapper.Extra.Utilities 5 | { 6 | public sealed class ArrayEqualityComparer : IEqualityComparer where T : struct 7 | { 8 | public static readonly IEqualityComparer Default = new ArrayEqualityComparer(); 9 | 10 | private ArrayEqualityComparer() 11 | { 12 | InitialHashCode = typeof(T).FullName.GetHashCode(); 13 | } 14 | 15 | private int InitialHashCode { get; } 16 | 17 | public bool Equals(T[] x, T[] y) 18 | { 19 | if (x != y) { 20 | if (x == null || y == null || x.Length != y.Length) 21 | return false; 22 | for (int i = 0; i < x.Length; i++) { 23 | if (!x[i].Equals(y[i])) 24 | return false; 25 | } 26 | } 27 | return true; 28 | } 29 | 30 | public int GetHashCode(T[] obj) 31 | { 32 | int hashCode = InitialHashCode; 33 | for (int i = 0; i < obj.Length; i++) { 34 | hashCode = hashCode * 67236819 + obj[i].GetHashCode(); 35 | } 36 | return hashCode; 37 | 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /ConsoleTests/Bad/Bad1.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Released under MIT License 3 | // License: https://opensource.org/licenses/MIT 4 | // Home page: https://github.com/ffhighwind/DapperExtraCRUD 5 | 6 | // Copyright(c) 2018 Wesley Hamilton 7 | 8 | // Permission is hereby granted, free of charge, to any person obtaining a copy 9 | // of this software and associated documentation files (the "Software"), to deal 10 | // in the Software without restriction, including without limitation the rights 11 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the Software is 13 | // furnished to do so, subject to the following conditions: 14 | 15 | // The above copyright notice and this permission notice shall be included in all 16 | // copies or substantial portions of the Software. 17 | 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | // SOFTWARE. 25 | #endregion 26 | 27 | 28 | namespace ConsoleTests 29 | { 30 | public class Bad1 31 | { 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /ConsoleTests/Bad/Bad2.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Released under MIT License 3 | // License: https://opensource.org/licenses/MIT 4 | // Home page: https://github.com/ffhighwind/DapperExtraCRUD 5 | 6 | // Copyright(c) 2018 Wesley Hamilton 7 | 8 | // Permission is hereby granted, free of charge, to any person obtaining a copy 9 | // of this software and associated documentation files (the "Software"), to deal 10 | // in the Software without restriction, including without limitation the rights 11 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the Software is 13 | // furnished to do so, subject to the following conditions: 14 | 15 | // The above copyright notice and this permission notice shall be included in all 16 | // copies or substantial portions of the Software. 17 | 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | // SOFTWARE. 25 | #endregion 26 | 27 | using Dapper.Extra.Annotations; 28 | 29 | namespace ConsoleTests 30 | { 31 | public class Bad2 32 | { 33 | [Key] 34 | public int AutoId { get; set; } 35 | [Key(false)] 36 | public string CompositeKey { get; set; } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /ConsoleTests/Bad/Bad3.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using Dapper.Extra.Annotations; 7 | 8 | namespace ConsoleTests 9 | { 10 | public class Bad3 11 | { 12 | public int ID; 13 | 14 | protected int Num; 15 | [Key] 16 | private bool Bool { get; } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /ConsoleTests/Bad/Bad4.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 ConsoleTests 8 | { 9 | public class Bad4 10 | { 11 | public static int ID { get; set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /ConsoleTests/Bad/Bad5.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 ConsoleTests 8 | { 9 | public class Bad5_ 10 | { 11 | public static int ID { private get; set; } 12 | } 13 | 14 | public class Bad5 : Bad5_ 15 | { 16 | public new int ID { get; } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /ConsoleTests/ConsoleTests.csproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | ProjectFiles 5 | 6 | -------------------------------------------------------------------------------- /ConsoleTests/Good/Dto10.cs: -------------------------------------------------------------------------------- 1 | namespace ConsoleTests 2 | { 3 | public class Dto10 4 | { 5 | private int id; 6 | private int ID { set => id = value; } 7 | private int Default { set => id = value; } 8 | } 9 | } -------------------------------------------------------------------------------- /ConsoleTests/Good/Dto11.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace ConsoleTests 4 | { 5 | public class Dto11 6 | { 7 | private int id; 8 | private int Dto11ID { set => id = value; } 9 | private int Default { set => id = value; } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /ConsoleTests/Good/Dto12.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace ConsoleTests 4 | { 5 | public class Dto12 6 | { 7 | private int id; 8 | public int Id { get; set; } 9 | private int Dto12ID { get; set; } 10 | private int Default { get; set; } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /ConsoleTests/Good/Dto13.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Dapper.Extra.Annotations; 3 | 4 | namespace ConsoleTests 5 | { 6 | public class Dto13 7 | { 8 | private int id; 9 | private int dto13ID { get; set; } 10 | [Column("Dto13ID")] 11 | public int MyId { get; set; } 12 | private int Default { get; set; } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /ConsoleTests/Good/Dto14.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel.DataAnnotations; 4 | 5 | namespace ConsoleTests 6 | { 7 | public class Dto14 8 | { 9 | [Key] 10 | [Required] 11 | public int MyID { get; set; } 12 | public string Name { get; set; } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /ConsoleTests/Good/Dto15.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel.DataAnnotations; 4 | 5 | namespace ConsoleTests 6 | { 7 | public class Dto15 8 | { 9 | [Required] 10 | public int MyID { get; set; } 11 | public string Name { get; set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /ConsoleTests/Good/IDto.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Released under MIT License 3 | // License: https://opensource.org/licenses/MIT 4 | // Home page: https://github.com/ffhighwind/DapperExtraCRUD 5 | 6 | // Copyright(c) 2018 Wesley Hamilton 7 | 8 | // Permission is hereby granted, free of charge, to any person obtaining a copy 9 | // of this software and associated documentation files (the "Software"), to deal 10 | // in the Software without restriction, including without limitation the rights 11 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the Software is 13 | // furnished to do so, subject to the following conditions: 14 | 15 | // The above copyright notice and this permission notice shall be included in all 16 | // copies or substantial portions of the Software. 17 | 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | // SOFTWARE. 25 | #endregion 26 | 27 | using System; 28 | using System.Collections.Generic; 29 | 30 | namespace ConsoleTests 31 | { 32 | public interface IDto : IComparable, IEquatable, IEqualityComparer 33 | { 34 | T UpdateRandomize(Random random); 35 | bool IsIdentical(T other); 36 | bool IsInserted(T other); 37 | bool IsUpdated(T other); 38 | string CreateTable(); 39 | T Clone(); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /ConsoleTests/Good/IDtoKey.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Released under MIT License 3 | // License: https://opensource.org/licenses/MIT 4 | // Home page: https://github.com/ffhighwind/DapperExtraCRUD 5 | 6 | // Copyright(c) 2018 Wesley Hamilton 7 | 8 | // Permission is hereby granted, free of charge, to any person obtaining a copy 9 | // of this software and associated documentation files (the "Software"), to deal 10 | // in the Software without restriction, including without limitation the rights 11 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the Software is 13 | // furnished to do so, subject to the following conditions: 14 | 15 | // The above copyright notice and this permission notice shall be included in all 16 | // copies or substantial portions of the Software. 17 | 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | // SOFTWARE. 25 | #endregion 26 | 27 | 28 | namespace ConsoleTests 29 | { 30 | public interface IDtoKey : IDto 31 | where T : IDtoKey 32 | { 33 | KeyType GetKey(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /ConsoleTests/Good/IFilter.cs: -------------------------------------------------------------------------------- 1 | namespace ConsoleTests 2 | { 3 | public interface IFilter where T : class 4 | { 5 | bool IsFiltered(T obj); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /ConsoleTests/Good/Test3.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Released under MIT License 3 | // License: https://opensource.org/licenses/MIT 4 | // Home page: https://github.com/ffhighwind/DapperExtraCRUD 5 | 6 | // Copyright(c) 2018 Wesley Hamilton 7 | 8 | // Permission is hereby granted, free of charge, to any person obtaining a copy 9 | // of this software and associated documentation files (the "Software"), to deal 10 | // in the Software without restriction, including without limitation the rights 11 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the Software is 13 | // furnished to do so, subject to the following conditions: 14 | 15 | // The above copyright notice and this permission notice shall be included in all 16 | // copies or substantial portions of the Software. 17 | 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | // SOFTWARE. 25 | #endregion 26 | 27 | using System; 28 | using System.Collections.Generic; 29 | using Dapper.Extra.Annotations; 30 | 31 | namespace ConsoleTests 32 | { 33 | public class Test3 : IDto 34 | { 35 | private static readonly IEqualityComparer Comparer = Dapper.Extra.ExtraCrud.EqualityComparer(); 36 | 37 | public Test3() { } 38 | public Test3(Random random) 39 | { 40 | Col1 = random.Next(); 41 | Col2 = random.Next().ToString(); 42 | Col3 = (float)random.NextDouble(); 43 | Col4 = random.Next() >= 0 ? random.Next() : (int?)null; 44 | } 45 | [Key] 46 | public int Col1 { get; set; } 47 | [Key] 48 | public string Col2 { get; set; } 49 | [Key] 50 | public float Col3 { get; set; } 51 | public int? Col4 { get; set; } 52 | 53 | public string CreateTable() 54 | { 55 | return @" 56 | CREATE TABLE [dbo].[Test3]( 57 | [Col1] [int] NOT NULL, 58 | [Col2] [nvarchar](50) NOT NULL, 59 | [Col3] [float] NOT NULL, 60 | [Col4] [int] NULL, 61 | CONSTRAINT [PK_Test3] PRIMARY KEY CLUSTERED 62 | ( 63 | [Col1] ASC, 64 | [Col2] ASC, 65 | [Col3] ASC 66 | )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] 67 | ) ON [PRIMARY] 68 | "; 69 | } 70 | 71 | public override bool Equals(object other) 72 | { 73 | return Equals(other as Test3); 74 | } 75 | 76 | public bool Equals(Test3 other) 77 | { 78 | return Comparer.Equals(this, other); 79 | } 80 | 81 | public bool Equals(Test3 x, Test3 y) 82 | { 83 | return Comparer.Equals(x, y); 84 | } 85 | 86 | public int GetHashCode(Test3 obj) 87 | { 88 | return Comparer.GetHashCode(obj); 89 | } 90 | 91 | public override int GetHashCode() 92 | { 93 | return Comparer.GetHashCode(this); 94 | } 95 | 96 | public int CompareTo(Test3 other) 97 | { 98 | int ret = Col1.CompareTo(other.Col1); 99 | if (ret == 0) { 100 | ret = string.Compare(Col2, Col2, StringComparison.OrdinalIgnoreCase); 101 | if (ret == 0) { 102 | ret = Col3.CompareTo(other.Col3); 103 | } 104 | } 105 | return ret; 106 | } 107 | 108 | public bool IsInserted(Test3 other) 109 | { 110 | return Equals(other); 111 | } 112 | 113 | public bool IsIdentical(Test3 other) 114 | { 115 | return other.Col1 == Col1 116 | && other.Col2 == Col2 117 | && other.Col3 == Col3 118 | && other.Col4 == Col4; 119 | } 120 | 121 | public Test3 UpdateRandomize(Random random) 122 | { 123 | Test3 clone = (Test3)MemberwiseClone(); 124 | clone.Col4 = random.Next(); 125 | return clone; 126 | } 127 | 128 | public bool IsUpdated(Test3 other) 129 | { 130 | return Equals(other) && Col4 == other.Col4; 131 | } 132 | 133 | public Test3 Clone() 134 | { 135 | return (Test3) MemberwiseClone(); 136 | } 137 | } 138 | } 139 | -------------------------------------------------------------------------------- /ConsoleTests/Good/Test3filter.cs: -------------------------------------------------------------------------------- 1 | namespace ConsoleTests 2 | { 3 | public class Test3filter : IFilter 4 | { 5 | public int Col1 { get; set; } 6 | //public string Col2 { get; set; } 7 | //public float Col3 { get; set; } 8 | public int? Col4 { get; set; } 9 | 10 | public bool IsFiltered(Test3 obj) 11 | { 12 | return obj.Col1 != default(int) 13 | && obj.Col2 == default(string) 14 | && obj.Col3 == default(float) 15 | && obj.Col4 != default(int?); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /ConsoleTests/Good/Test7.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Dapper.Extra.Annotations; 4 | 5 | namespace ConsoleTests 6 | { 7 | public enum Test7Type 8 | { 9 | ID0, 10 | ID1, 11 | ID2, 12 | ID3, 13 | ID4, 14 | ID5, 15 | ID6, 16 | ID7, 17 | ID8, 18 | ID9, 19 | ID10, 20 | ID11, 21 | ID12, 22 | ID13, 23 | ID14, 24 | ID15, 25 | ID16, 26 | ID17, 27 | ID18, 28 | ID19, 29 | } 30 | 31 | public class Test7 : IDtoKey 32 | { 33 | private static readonly IEqualityComparer Comparer = Dapper.Extra.ExtraCrud.EqualityComparer(); 34 | 35 | public Test7() { } 36 | 37 | public Test7(Random random) 38 | { 39 | ID = (Test7Type)random.Next(); 40 | Value = (random.Next() % 100) > 35 ? (Test7Type?) (random.Next() % (int) Test7Type.ID19) : null; 41 | } 42 | 43 | [Key(false)] 44 | public Test7Type ID { get; set; } 45 | 46 | public Test7Type? Value { get; set; } 47 | 48 | public bool? Default { get; set; } 49 | 50 | public Test7 Clone() 51 | { 52 | return (Test7) MemberwiseClone(); 53 | } 54 | 55 | public int CompareTo(Test7 other) 56 | { 57 | return ID.CompareTo(other.ID); 58 | } 59 | 60 | public string CreateTable() 61 | { 62 | return @" 63 | CREATE TABLE [dbo].[Test7]( 64 | [ID] [int] NOT NULL, 65 | [Value] [int] NULL, 66 | [Default] [bit] NULL, 67 | CONSTRAINT [PK_Test7] PRIMARY KEY CLUSTERED 68 | ( 69 | [ID] ASC 70 | )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] 71 | ) ON [PRIMARY]"; 72 | } 73 | 74 | public override bool Equals(object other) 75 | { 76 | return Equals(other as Test7); 77 | } 78 | 79 | public bool Equals(Test7 other) 80 | { 81 | return Comparer.Equals(this, other); 82 | } 83 | 84 | public bool Equals(Test7 x, Test7 y) 85 | { 86 | return Comparer.Equals(x, y); 87 | } 88 | 89 | public int GetHashCode(Test7 obj) 90 | { 91 | return Comparer.GetHashCode(obj); 92 | } 93 | 94 | public override int GetHashCode() 95 | { 96 | return Comparer.GetHashCode(this); 97 | } 98 | 99 | public Test7Type GetKey() 100 | { 101 | return ID; 102 | } 103 | 104 | public bool IsIdentical(Test7 other) 105 | { 106 | return Equals(other); 107 | } 108 | 109 | public bool IsInserted(Test7 other) 110 | { 111 | return Equals(other); 112 | } 113 | 114 | public bool IsUpdated(Test7 other) 115 | { 116 | return Equals(other); 117 | } 118 | 119 | public Test7 UpdateRandomize(Random random) 120 | { 121 | return Clone(); 122 | } 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /ConsoleTests/Good/Test7filter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace ConsoleTests 4 | { 5 | public class Test7filter : IFilter 6 | { 7 | public Test7Type ID { get; set; } 8 | 9 | public bool IsFiltered(Test7 obj) 10 | { 11 | return obj.Value == null; 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /ConsoleTests/Good/Test8filter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace ConsoleTests 4 | { 5 | public class Test8filter : IFilter 6 | { 7 | //public long ID { get; set; } 8 | public string Varchar { get; set; } // [varchar] (25) NOT NULL 9 | //public long? Quantity { get; set; } // [Quantity] [bigint] NULL, 10 | public int? Int { get; set; } // [Int] [int] NULL 11 | public short? Small { get; set; } // [Small] [smallint] NULL 12 | //public byte? Tiny { get; set; } // [Tiny] [tinyint] NULL 13 | public bool? Bit { get; set; } // [Bit] [bit] NULL 14 | public Guid? Guid { get; set; } // [Guid] [uniqueidentifier] NULL 15 | public decimal? Money { get; set; } // [Money] [money] NULL 16 | public float? Real { get; set; } // [Real] [real] NULL 17 | public char? Char { get; set; } // [Char] [char](1) NULL 18 | public float? Float { get; set; } // [Float] [float] NULL 19 | public decimal? Decimal16_3 { get; set; } // [Decimal16_3] [decimal](16, 3) NULL 20 | public DateTimeOffset? DateTimeOffset { get; set; } // [DateTimeOffset] [datetimeoffset] (7) NULL 21 | //public DateTime? Date { get; set; } // [Date] [date] NULL 22 | public string Char12 { get; set; } // [Char12] [char](12) NULL 23 | public decimal? Numeric13_5 { get; set; } // [Numeric13_5] [numeric] (13, 5) NULL 24 | public DateTime? DateTime2_7 { get; set; } // [DateTime2_7] [datetime2] (7) NULL 25 | //public DateTime? DateTime { get; set; } // [DateTime] [datetime] NULL 26 | public byte[] Binary35 { get; set; } // [Binary35] [binary] (35) NULL 27 | public DateTime? SmallDateTime { get; set; } // [SmallDateTime] [smalldatetime] NULL 28 | //public byte[] VarBinary25 { get; set; } 29 | public decimal SmallMoney { get; set; } 30 | public DateTime? Date { get; set; } 31 | 32 | public TimeSpan Time { get; set; } 33 | 34 | public bool IsFiltered(Test8 obj) 35 | { 36 | return obj.ID == 0 37 | && obj.Quantity == null 38 | && obj.Date != null 39 | && obj.DateTime == null 40 | && obj.Char != null 41 | && obj.VarBinary25 == null 42 | && obj.Time != default(TimeSpan) 43 | && obj.TimeStamp == null; 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /ConsoleTests/Good/Test9.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Dapper.Extra.Annotations; 4 | 5 | namespace ConsoleTests 6 | { 7 | public class Test9 : IDtoKey 8 | { 9 | private static readonly IEqualityComparer Comparer = Dapper.Extra.ExtraCrud.EqualityComparer(); 10 | 11 | public Test9() { } 12 | public Test9(Random random) 13 | { 14 | ID = new byte[random.Next() % 15 + 20]; 15 | random.NextBytes(ID); 16 | Name = random.Next().ToString(); 17 | } 18 | 19 | [Key(false)] 20 | public byte[] ID { get; set; } 21 | public string Name { get; set; } 22 | 23 | public Test9 Clone() 24 | { 25 | Test9 clone = (Test9) MemberwiseClone(); 26 | clone.ID = new byte[ID.Length]; 27 | Array.Copy(ID, 0, clone.ID, 0, ID.Length); 28 | return clone; 29 | } 30 | 31 | public int CompareTo(Test9 other) 32 | { 33 | int cmp = Name.CompareTo(other.Name); 34 | if (cmp == 0) { 35 | cmp = ID.Length.CompareTo(other.ID.Length); 36 | if (cmp == 0) { 37 | for (int i = 0; i < ID.Length; i++) { 38 | cmp = ID[i].CompareTo(other.ID[i]); 39 | if (cmp != 0) 40 | break; 41 | } 42 | } 43 | } 44 | return cmp; 45 | } 46 | 47 | public string CreateTable() 48 | { 49 | return @" 50 | CREATE TABLE [dbo].[Test9]( 51 | [ID] [varbinary](35) NOT NULL, 52 | [Name] [varchar](50) NOT NULL, 53 | CONSTRAINT [PK_Test9] PRIMARY KEY CLUSTERED 54 | ( 55 | [ID] ASC 56 | )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] 57 | ) ON [PRIMARY]"; 58 | } 59 | 60 | public override int GetHashCode() 61 | { 62 | return Comparer.GetHashCode(this); 63 | } 64 | 65 | public override bool Equals(object obj) 66 | { 67 | return Equals(obj as Test9); 68 | } 69 | 70 | public bool Equals(Test9 other) 71 | { 72 | return other != null && Comparer.Equals(this, other); 73 | } 74 | 75 | public bool Equals(Test9 x, Test9 y) 76 | { 77 | return Comparer.Equals(x, y); 78 | } 79 | 80 | public int GetHashCode(Test9 obj) 81 | { 82 | return Comparer.GetHashCode(obj); 83 | } 84 | 85 | public byte[] GetKey() 86 | { 87 | return ID; 88 | } 89 | 90 | public bool IsIdentical(Test9 other) 91 | { 92 | if (Name != other.Name) 93 | return false; 94 | if (other.ID != ID) { 95 | if (other.ID == null || ID == null || other.ID.Length != ID.Length) 96 | return false; 97 | for (int i = 0; i < ID.Length; i++) { 98 | if (ID[i] != other.ID[i]) 99 | return false; 100 | } 101 | } 102 | return true; 103 | } 104 | 105 | public bool IsInserted(Test9 other) 106 | { 107 | return IsIdentical(other); 108 | } 109 | 110 | public bool IsUpdated(Test9 other) 111 | { 112 | return IsIdentical(other); 113 | } 114 | 115 | public Test9 UpdateRandomize(Random random) 116 | { 117 | Test9 clone = Clone(); 118 | clone.Name = random.Next().ToString(); 119 | return clone; 120 | } 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /ConsoleTests/Good/Test9filter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace ConsoleTests 4 | { 5 | public class Test9filter : IFilter 6 | { 7 | public string Name { get; set; } 8 | 9 | public bool IsFiltered(Test9 obj) 10 | { 11 | return obj.ID == null && obj.Name != null; 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /ConsoleTests/Good/TestDTO.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Released under MIT License 3 | // License: https://opensource.org/licenses/MIT 4 | // Home page: https://github.com/ffhighwind/DapperExtraCRUD 5 | 6 | // Copyright(c) 2018 Wesley Hamilton 7 | 8 | // Permission is hereby granted, free of charge, to any person obtaining a copy 9 | // of this software and associated documentation files (the "Software"), to deal 10 | // in the Software without restriction, including without limitation the rights 11 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the Software is 13 | // furnished to do so, subject to the following conditions: 14 | 15 | // The above copyright notice and this permission notice shall be included in all 16 | // copies or substantial portions of the Software. 17 | 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | // SOFTWARE. 25 | #endregion 26 | 27 | using System; 28 | using System.Collections.Generic; 29 | using Dapper.Extra.Annotations; 30 | 31 | namespace ConsoleTests 32 | { 33 | [Table("Test")] 34 | public class TestDTO : IDtoKey 35 | { 36 | private static readonly IEqualityComparer Comparer = Dapper.Extra.ExtraCrud.EqualityComparer(); 37 | 38 | public TestDTO() { } 39 | public TestDTO(Random random) 40 | { 41 | Name = random.Next().ToString(); 42 | CreatedDt = DateTime.FromOADate(random.NextDouble()); 43 | } 44 | 45 | [Key] 46 | public int ID { get; internal set; } 47 | 48 | [Column("FirstName")] 49 | public string Name { get; set; } 50 | [IgnoreInsert("getdate()", false)] 51 | [IgnoreUpdate("getdate()", false)] 52 | public DateTime? CreatedDt { get; private set; } 53 | 54 | public bool IsActive { get; protected set; } 55 | 56 | public TestDTO Test { get; set; } 57 | 58 | public string CreateTable() 59 | { 60 | return @" 61 | CREATE TABLE [dbo].[Test]( 62 | [ID] [int] IDENTITY(1,1) NOT NULL, 63 | [FirstName] [varchar](max) NOT NULL, 64 | [CreatedDt] [datetime2](7) NULL, 65 | [IsActive] [bit] NOT NULL, 66 | CONSTRAINT [PK_Test_1] PRIMARY KEY CLUSTERED 67 | ( 68 | [ID] ASC 69 | )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] 70 | ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]"; 71 | } 72 | 73 | public override bool Equals(object other) 74 | { 75 | return Equals(other as TestDTO); 76 | } 77 | 78 | public bool Equals(TestDTO other) 79 | { 80 | return Comparer.Equals(this, other); 81 | } 82 | 83 | public bool Equals(TestDTO x, TestDTO y) 84 | { 85 | return Comparer.Equals(x, y); 86 | } 87 | 88 | public int GetHashCode(TestDTO obj) 89 | { 90 | return Comparer.GetHashCode(obj); 91 | } 92 | 93 | public override int GetHashCode() 94 | { 95 | return Comparer.GetHashCode(this); 96 | } 97 | 98 | public int CompareTo(TestDTO other) 99 | { 100 | return ID.CompareTo(other.ID); 101 | } 102 | 103 | public int GetKey() 104 | { 105 | return ID; 106 | } 107 | 108 | public bool IsIdentical(TestDTO other) 109 | { 110 | return other.ID == ID 111 | && other.Name == Name 112 | && other.CreatedDt == CreatedDt; 113 | } 114 | 115 | public bool IsInserted(TestDTO other) 116 | { 117 | return ID == other.ID 118 | && Name == other.Name 119 | && CreatedDt != other.CreatedDt 120 | && ID != 0; 121 | } 122 | 123 | public TestDTO UpdateRandomize(Random random) 124 | { 125 | TestDTO clone = (TestDTO)MemberwiseClone(); 126 | clone.Name = random.Next().ToString(); 127 | return clone; 128 | } 129 | 130 | public bool IsUpdated(TestDTO other) 131 | { 132 | return Equals(other) && Name == other.Name; 133 | } 134 | 135 | public TestDTO Clone() 136 | { 137 | return (TestDTO)MemberwiseClone(); 138 | } 139 | } 140 | } 141 | -------------------------------------------------------------------------------- /ConsoleTests/Good/TestDTO2.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Released under MIT License 3 | // License: https://opensource.org/licenses/MIT 4 | // Home page: https://github.com/ffhighwind/DapperExtraCRUD 5 | 6 | // Copyright(c) 2018 Wesley Hamilton 7 | 8 | // Permission is hereby granted, free of charge, to any person obtaining a copy 9 | // of this software and associated documentation files (the "Software"), to deal 10 | // in the Software without restriction, including without limitation the rights 11 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the Software is 13 | // furnished to do so, subject to the following conditions: 14 | 15 | // The above copyright notice and this permission notice shall be included in all 16 | // copies or substantial portions of the Software. 17 | 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | // SOFTWARE. 25 | #endregion 26 | 27 | using System; 28 | using System.Collections.Generic; 29 | using Dapper.Extra.Annotations; 30 | 31 | namespace ConsoleTests 32 | { 33 | [Table("Test2")] 34 | public class TestDTO2 : IDto 35 | { 36 | private static readonly IEqualityComparer Comparer = Dapper.Extra.ExtraCrud.EqualityComparer(); 37 | 38 | public TestDTO2() { } 39 | public TestDTO2(Random random) 40 | { 41 | Col1 = random.Next(); 42 | Col2 = random.Next().ToString(); 43 | Col3 = (float)random.NextDouble(); 44 | } 45 | 46 | [Key(false)] 47 | public int Col1 { get; set; } 48 | [Key(false)] 49 | public string Col2 { get; set; } 50 | [Key(false)] 51 | public float Col3 { get; set; } 52 | 53 | public string CreateTable() 54 | { 55 | return @" 56 | CREATE TABLE [dbo].[Test2]( 57 | [Col1] [int] NOT NULL, 58 | [Col2] [nvarchar](50) NOT NULL, 59 | [Col3] [float] NOT NULL, 60 | CONSTRAINT [PK_Test2] PRIMARY KEY CLUSTERED 61 | ( 62 | [Col1] ASC, 63 | [Col2] ASC, 64 | [Col3] ASC 65 | )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] 66 | ) ON [PRIMARY]"; 67 | } 68 | 69 | public override bool Equals(object other) 70 | { 71 | return Equals(other as TestDTO2); 72 | } 73 | 74 | public bool Equals(TestDTO2 other) 75 | { 76 | return Comparer.Equals(this, other); 77 | } 78 | 79 | public bool Equals(TestDTO2 x, TestDTO2 y) 80 | { 81 | return Comparer.Equals(x, y); 82 | } 83 | 84 | public int GetHashCode(TestDTO2 obj) 85 | { 86 | return Comparer.GetHashCode(obj); 87 | } 88 | 89 | public override int GetHashCode() 90 | { 91 | return Comparer.GetHashCode(this); 92 | } 93 | 94 | public int CompareTo(TestDTO2 other) 95 | { 96 | int ret = Col1.CompareTo(other.Col1); 97 | if (ret == 0) { 98 | ret = string.Compare(Col2, other.Col2, StringComparison.OrdinalIgnoreCase); 99 | if (ret == 0) { 100 | ret = Col3.CompareTo(other.Col3); 101 | } 102 | } 103 | return ret; 104 | } 105 | 106 | public bool IsInserted(TestDTO2 other) 107 | { 108 | return Equals(other); 109 | } 110 | 111 | public bool IsIdentical(TestDTO2 other) 112 | { 113 | return Equals(other); 114 | } 115 | 116 | public TestDTO2 UpdateRandomize(Random random) 117 | { 118 | TestDTO2 clone = (TestDTO2)MemberwiseClone(); 119 | return clone; 120 | } 121 | 122 | public bool IsUpdated(TestDTO2 other) 123 | { 124 | return Equals(other); 125 | } 126 | 127 | public TestDTO2 Clone() 128 | { 129 | return (TestDTO2)MemberwiseClone(); 130 | } 131 | } 132 | } 133 | -------------------------------------------------------------------------------- /ConsoleTests/Good/TestDTO2filter.cs: -------------------------------------------------------------------------------- 1 | namespace ConsoleTests 2 | { 3 | public class TestDTO2filter : IFilter 4 | { 5 | public int Col1 { get; set; } 6 | //public string Col2 { get; set; } 7 | //public float Col3 { get; set; } 8 | 9 | public bool IsFiltered(TestDTO2 obj) 10 | { 11 | return obj.Col1 != default(int) 12 | && obj.Col2 == default(string) 13 | && obj.Col3 == default(float); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /ConsoleTests/Good/TestDTO4.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Released under MIT License 3 | // License: https://opensource.org/licenses/MIT 4 | // Home page: https://github.com/ffhighwind/DapperExtraCRUD 5 | 6 | // Copyright(c) 2018 Wesley Hamilton 7 | 8 | // Permission is hereby granted, free of charge, to any person obtaining a copy 9 | // of this software and associated documentation files (the "Software"), to deal 10 | // in the Software without restriction, including without limitation the rights 11 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the Software is 13 | // furnished to do so, subject to the following conditions: 14 | 15 | // The above copyright notice and this permission notice shall be included in all 16 | // copies or substantial portions of the Software. 17 | 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | // SOFTWARE. 25 | #endregion 26 | 27 | using System; 28 | using System.Collections.Generic; 29 | using Dapper.Extra.Annotations; 30 | 31 | namespace ConsoleTests 32 | { 33 | [Table("Test4", "guest")] 34 | public class TestDTO4 : IDtoKey 35 | { 36 | private static readonly IEqualityComparer Comparer = Dapper.Extra.ExtraCrud.EqualityComparer(); 37 | 38 | public TestDTO4() { } 39 | public TestDTO4(Random random) 40 | { 41 | ID = random.Next(); 42 | FirstName = random.Next().ToString(); 43 | LastName = random.Next().ToString(); 44 | } 45 | 46 | [Key] 47 | public int ID { get; set; } 48 | 49 | [MatchDelete] 50 | public string FirstName { get; set; } 51 | [MatchUpdate] 52 | public string LastName { get; set; } 53 | 54 | public string CreateTable() 55 | { 56 | return @" 57 | CREATE TABLE [guest].[Test4]( 58 | [ID] [int] IDENTITY(1,1) NOT NULL, 59 | [FirstName] [varchar](max) NOT NULL, 60 | [LastName] [varchar](max) NOT NULL, 61 | CONSTRAINT [PK_Test4] PRIMARY KEY CLUSTERED 62 | ( 63 | [ID] ASC 64 | )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] 65 | ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]"; 66 | } 67 | 68 | public override bool Equals(object other) 69 | { 70 | return Equals(other as TestDTO4); 71 | } 72 | 73 | public bool Equals(TestDTO4 other) 74 | { 75 | return Comparer.Equals(this, other); 76 | } 77 | 78 | public bool Equals(TestDTO4 x, TestDTO4 y) 79 | { 80 | return Comparer.Equals(x, y); 81 | } 82 | 83 | public int GetHashCode(TestDTO4 obj) 84 | { 85 | return Comparer.GetHashCode(obj); 86 | } 87 | 88 | public override int GetHashCode() 89 | { 90 | return Comparer.GetHashCode(this); 91 | } 92 | 93 | public int CompareTo(TestDTO4 other) 94 | { 95 | return ID.CompareTo(other.ID); 96 | } 97 | 98 | public int GetKey() 99 | { 100 | return ID; 101 | } 102 | 103 | public bool IsIdentical(TestDTO4 other) 104 | { 105 | return other.ID == ID 106 | && other.FirstName == FirstName 107 | && other.LastName == LastName; 108 | } 109 | 110 | public bool IsInserted(TestDTO4 other) 111 | { 112 | return Equals(other) && ID != 0; 113 | } 114 | 115 | 116 | public bool IsUpdated(TestDTO4 other) 117 | { 118 | return Equals(other) && FirstName == other.FirstName; 119 | } 120 | 121 | public TestDTO4 UpdateRandomize(Random random) 122 | { 123 | TestDTO4 clone = (TestDTO4)MemberwiseClone(); 124 | clone.FirstName = random.Next().ToString(); 125 | return clone; 126 | } 127 | 128 | public TestDTO4 Clone() 129 | { 130 | return (TestDTO4)MemberwiseClone(); 131 | } 132 | } 133 | } 134 | -------------------------------------------------------------------------------- /ConsoleTests/Good/TestDTO4filter.cs: -------------------------------------------------------------------------------- 1 | namespace ConsoleTests 2 | { 3 | public class TestDTO4filter : IFilter 4 | { 5 | //public int ID { get; set; } 6 | 7 | //public string FirstName { get; set; } 8 | public string LastName { get; set; } 9 | 10 | public bool IsFiltered(TestDTO4 obj) 11 | { 12 | return obj.ID == default(int) 13 | && obj.LastName != default(string) 14 | && obj.FirstName == default(string); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /ConsoleTests/Good/TestDTO5.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Dapper.Extra.Annotations; 4 | 5 | namespace ConsoleTests 6 | { 7 | public class TestDTO5 : IDtoKey 8 | { 9 | private static readonly IEqualityComparer Comparer = Dapper.Extra.ExtraCrud.EqualityComparer(); 10 | 11 | public TestDTO5() { } 12 | 13 | public TestDTO5(Random random) 14 | { 15 | Name = random.Next().ToString(); 16 | Created = DateTime.FromOADate(random.NextDouble()); 17 | Modified = DateTime.FromOADate(random.NextDouble()); 18 | Modified2 = DateTime.FromOADate(random.NextDouble()); 19 | } 20 | 21 | public int ID { get; set; } 22 | 23 | [Column("Full Name")] 24 | public string Name { get; set; } 25 | 26 | internal DateTime Created { get; private set; } 27 | 28 | [MatchUpdate("getdate()", true)] 29 | [IgnoreInsert("getdate()")] 30 | public DateTime Modified { get; set; } 31 | 32 | 33 | [MatchUpdate(null, true)] 34 | [IgnoreInsert(null)] 35 | public DateTime Modified2 { get; set; } 36 | 37 | public TestDTO5 Clone() 38 | { 39 | return (TestDTO5)MemberwiseClone(); 40 | } 41 | 42 | public int CompareTo(TestDTO5 other) 43 | { 44 | return ID.CompareTo(other.ID); 45 | } 46 | 47 | public string CreateTable() 48 | { 49 | return @" 50 | CREATE TABLE [dbo].[TestDTO5]( 51 | [ID] [int] IDENTITY(1,1) NOT NULL, 52 | [Full Name] [varchar](255) NOT NULL, 53 | [Created] [datetime2](7) NOT NULL, 54 | [Modified] [datetime] NOT NULL, 55 | [Modified2] [datetime2](2) NOT NULL, 56 | CONSTRAINT [PK_TestDTO5] PRIMARY KEY CLUSTERED 57 | ( 58 | [ID] ASC 59 | )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] 60 | ) ON [PRIMARY]; 61 | 62 | ALTER TABLE [dbo].[TestDTO5] ADD CONSTRAINT [DF_TestDTO5_Created] DEFAULT (getdate()) FOR [Created]; 63 | 64 | ALTER TABLE [dbo].[TestDTO5] ADD CONSTRAINT [DF_TestDTO5_Modified] DEFAULT (getdate()) FOR [Modified]; 65 | 66 | ALTER TABLE [dbo].[TestDTO5] ADD CONSTRAINT [DF_TestDTO5_Modified2] DEFAULT (getdate()) FOR [Modified2];"; 67 | } 68 | 69 | public override bool Equals(object other) 70 | { 71 | return Equals(other as TestDTO5); 72 | } 73 | 74 | public bool Equals(TestDTO5 other) 75 | { 76 | return Comparer.Equals(this, other); 77 | } 78 | 79 | public bool Equals(TestDTO5 x, TestDTO5 y) 80 | { 81 | return Comparer.Equals(x, y); 82 | } 83 | 84 | public int GetHashCode(TestDTO5 obj) 85 | { 86 | return Comparer.GetHashCode(obj); 87 | } 88 | 89 | public override int GetHashCode() 90 | { 91 | return Comparer.GetHashCode(this); 92 | } 93 | 94 | public int GetKey() 95 | { 96 | return ID; 97 | } 98 | 99 | public bool IsIdentical(TestDTO5 other) 100 | { 101 | bool a1 = ID == other.ID; 102 | bool a2 = Name == other.Name; 103 | bool a3 = Created == other.Created; 104 | //bool a4 = Modified == other.Modified; // auto-syncd 105 | return a1 && a2 && a3; 106 | } 107 | 108 | public bool IsInserted(TestDTO5 other) 109 | { 110 | return Equals(other) && ID != 0; 111 | } 112 | 113 | public bool IsUpdated(TestDTO5 other) 114 | { 115 | return Equals(other) && Name == other.Name; 116 | } 117 | 118 | public TestDTO5 UpdateRandomize(Random random) 119 | { 120 | TestDTO5 clone = (TestDTO5)MemberwiseClone(); 121 | clone.Name = random.Next().ToString(); 122 | return clone; 123 | } 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /ConsoleTests/Good/TestDTO5filter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace ConsoleTests 4 | { 5 | public class TestDTO5filter : IFilter 6 | { 7 | public string Name { get; set; } 8 | 9 | public bool IsFiltered(TestDTO5 obj) 10 | { 11 | return obj.ID == default(int) 12 | && obj.Modified == default(DateTime) 13 | && obj.Modified2 == default(DateTime) 14 | && obj.Created == default(DateTime) 15 | && obj.Name != default(string); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /ConsoleTests/Good/TestDTO6.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Dapper.Extra.Annotations; 4 | 5 | namespace ConsoleTests 6 | { 7 | public class TestDTO6 : IDtoKey 8 | { 9 | private static readonly IEqualityComparer Comparer = Dapper.Extra.ExtraCrud.EqualityComparer(); 10 | 11 | private static readonly string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; 12 | 13 | 14 | private static string RandomString(int length, Random random) 15 | { 16 | char[] ch = new char[length]; 17 | for(int i = 0; i < length; i++) { 18 | ch[i] = chars[random.Next() % chars.Length]; 19 | } 20 | return new string(ch); 21 | } 22 | 23 | public TestDTO6() { } 24 | 25 | public TestDTO6(Random random) 26 | { 27 | ID = RandomString(8 + random.Next() % 15, random); 28 | Value = random.Next(); 29 | } 30 | 31 | [Key] 32 | public string ID { get; set; } 33 | 34 | public int Value { get; set; } 35 | 36 | public TestDTO6 Clone() 37 | { 38 | return (TestDTO6) MemberwiseClone(); 39 | } 40 | 41 | public int CompareTo(TestDTO6 other) 42 | { 43 | return ID.CompareTo(other.ID); 44 | } 45 | 46 | public string CreateTable() 47 | { 48 | return @" 49 | CREATE TABLE [dbo].[TestDTO6]( 50 | [ID] [varchar](24) NOT NULL, 51 | [Value] [int] NOT NULL, 52 | CONSTRAINT [PK_TestDTO6] PRIMARY KEY CLUSTERED 53 | ( 54 | [ID] ASC 55 | )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] 56 | ) ON [PRIMARY]"; 57 | } 58 | 59 | public override bool Equals(object other) 60 | { 61 | return Equals(other as TestDTO6); 62 | } 63 | 64 | public bool Equals(TestDTO6 other) 65 | { 66 | return Comparer.Equals(this, other); 67 | } 68 | 69 | public bool Equals(TestDTO6 x, TestDTO6 y) 70 | { 71 | return Comparer.Equals(x, y); 72 | } 73 | 74 | public int GetHashCode(TestDTO6 obj) 75 | { 76 | return Comparer.GetHashCode(obj); 77 | } 78 | 79 | public override int GetHashCode() 80 | { 81 | return Comparer.GetHashCode(this); 82 | } 83 | 84 | public string GetKey() 85 | { 86 | return ID; 87 | } 88 | 89 | public bool IsIdentical(TestDTO6 other) 90 | { 91 | return Equals(other) && Value == other.Value; 92 | } 93 | 94 | public bool IsInserted(TestDTO6 other) 95 | { 96 | return IsIdentical(other); 97 | } 98 | 99 | public bool IsUpdated(TestDTO6 other) 100 | { 101 | return IsIdentical(other); 102 | } 103 | 104 | public TestDTO6 UpdateRandomize(Random random) 105 | { 106 | TestDTO6 value = (TestDTO6)MemberwiseClone(); 107 | ID = random.Next() % 2 == 0 ? ID.ToLower() : ID.ToUpper(); 108 | value.Value = random.Next(); 109 | return value; 110 | } 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /ConsoleTests/Good/TestDTO6filter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Dapper.Extra.Annotations; 3 | 4 | namespace ConsoleTests 5 | { 6 | public class TestDTO6filter : IFilter 7 | { 8 | public int Value { get; set; } 9 | 10 | public bool IsFiltered(TestDTO6 obj) 11 | { 12 | return obj.ID == null && obj.Value != 0; 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /ConsoleTests/Good/TestDTOfilter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace ConsoleTests 4 | { 5 | public class TestDTOfilter : IFilter 6 | { 7 | //public int ID { get; set; } 8 | 9 | //public string Name { get; set; } 10 | public DateTime? CreatedDt { get; set; } 11 | 12 | public bool IsFiltered(TestDTO obj) 13 | { 14 | return obj.CreatedDt != null 15 | && obj.CreatedDt != default(DateTime) 16 | && obj.ID == default(int) 17 | && obj.Name == default(string) 18 | && obj.IsActive == default(bool); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /ConsoleTests/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | // General Information about an assembly is controlled through the following 5 | // set of attributes. Change these attribute values to modify the information 6 | // associated with an assembly. 7 | [assembly: AssemblyTitle("ConsoleTests")] 8 | [assembly: AssemblyDescription("")] 9 | [assembly: AssemblyConfiguration("")] 10 | [assembly: AssemblyCompany("")] 11 | [assembly: AssemblyProduct("ConsoleTests")] 12 | [assembly: AssemblyCopyright("Copyright © 2019")] 13 | [assembly: AssemblyTrademark("")] 14 | [assembly: AssemblyCulture("")] 15 | 16 | // Setting ComVisible to false makes the types in this assembly not visible 17 | // to COM components. If you need to access a type in this assembly from 18 | // COM, set the ComVisible attribute to true on that type. 19 | [assembly: ComVisible(false)] 20 | 21 | // The following GUID is for the ID of the typelib if this project is exposed to COM 22 | [assembly: Guid("965bb116-b0e0-4bac-b1d3-c1f573420f37")] 23 | 24 | // Version information for an assembly consists of the following four values: 25 | // 26 | // Major Version 27 | // Minor Version 28 | // Build Number 29 | // Revision 30 | // 31 | // You can specify all the values or you can default the Build and Revision Numbers 32 | // by using the '*' as shown below: 33 | // [assembly: AssemblyVersion("1.0.*")] 34 | [assembly: AssemblyVersion("1.0.0.0")] 35 | [assembly: AssemblyFileVersion("1.0.0.0")] 36 | -------------------------------------------------------------------------------- /ConsoleTests/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /DapperExtraCRUD.Cache.Example/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /DapperExtraCRUD.Cache.Example/DapperExtraCRUD.Cache.Example.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {0BE78AF8-2899-4EC8-A4F2-E4FB33D59B21} 8 | Exe 9 | DapperExtraCRUD.Cache.Example 10 | DapperExtraCRUD.Cache.Example 11 | v4.6.1 12 | 512 13 | true 14 | true 15 | 16 | 17 | AnyCPU 18 | true 19 | full 20 | false 21 | bin\Debug\ 22 | DEBUG;TRACE 23 | prompt 24 | 4 25 | 26 | 27 | AnyCPU 28 | pdbonly 29 | true 30 | bin\Release\ 31 | TRACE 32 | prompt 33 | 4 34 | 35 | 36 | 37 | ..\packages\Dapper.StrongName.2.0.30\lib\net461\Dapper.StrongName.dll 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | {3059ba7e-5590-4bbc-a38e-1aedc7d8a8a1} 59 | DapperExtraCRUD.Cache 60 | 61 | 62 | {4dbe71c1-2ecd-4192-bc66-e4d1c8dcec08} 63 | DapperExtraCRUD 64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /DapperExtraCRUD.Cache.Example/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Data.SqlClient; 3 | using Dapper.Extra.Annotations; 4 | using Dapper.Extra.Cache; 5 | using Dapper; 6 | 7 | namespace Example 8 | { 9 | [Table("Employees")] 10 | public class Employee 11 | { 12 | [Key] 13 | public int EmployeeID { get; set; } 14 | public string UserName { get; set; } 15 | public string FirstName { get; set; } 16 | public string LastName { get; set; } 17 | public DateTime HireDate { get; set; } 18 | public int ManagerID { get; set; } 19 | public DateTime DateOfBirth { get; set; } 20 | [IgnoreInsert("getdate()")] 21 | [MatchUpdate("getdate()")] 22 | [AutoSync(syncInsert: true, syncUpdate: true)] 23 | public DateTime ModifiedDate { get; set; } 24 | [IgnoreInsert("getdate()", true)] 25 | [IgnoreUpdate] 26 | public DateTime CreatedDate { get; set; } 27 | } 28 | 29 | public class EmployeeItem : CacheItem 30 | { 31 | public int ID => CacheValue.EmployeeID; 32 | public string UserName => CacheValue.UserName; 33 | public string Name => CacheValue.FirstName + " " + CacheValue.LastName; 34 | public DateTime HireDate => CacheValue.HireDate; 35 | public EmployeeItem Manager => LazyManager.Value; 36 | public DateTime DOB => CacheValue.DateOfBirth; 37 | public double Age => (DateTime.Today - CacheValue.DateOfBirth).TotalDays / 365.0; 38 | public DateTime ModifiedDate => CacheValue.ModifiedDate; 39 | public DateTime CreatedDate => CacheValue.CreatedDate; 40 | private Lazy LazyManager; 41 | protected override void OnValueChanged() 42 | { 43 | // Lazy is required here or this could be costly 44 | LazyManager = new Lazy(() => DB.Employees[CacheValue.ManagerID], false); 45 | } 46 | 47 | public bool Save() 48 | { 49 | // returns false if deleted or the row was not modified 50 | return DB.Employees.Update(CacheValue); 51 | } 52 | 53 | public bool Load() 54 | { 55 | EmployeeItem value = DB.Employees.Get(CacheValue); 56 | return value == this; 57 | } 58 | } 59 | 60 | public static class DB 61 | { 62 | private const string ConnString = "Server=myServerAddress;Database=myDataBase;User Id=myUsername;Password=myPassword;"; 63 | private static readonly DbCache Cache = new DbCache(ConnString); 64 | public static readonly DbCacheTable Employees = Cache.CreateTable(); 65 | 66 | public static DateTime GetDate() 67 | { 68 | using (SqlConnection conn = new SqlConnection(ConnString)) { 69 | // getdate() could be replaced by SqlAdapter.CurrentDateTime 70 | return conn.QueryFirst("select getdate()"); 71 | } 72 | } 73 | } 74 | 75 | public static class Program 76 | { 77 | public static void Main() 78 | { 79 | DB.Employees.GetList(); // caches all employees in the database 80 | 81 | try { 82 | using (DbCacheTransaction transaction = DB.Employees.BeginTransaction()) { 83 | Employee emp = new Employee() { 84 | DateOfBirth = new DateTime(2000, 2, 15), 85 | FirstName = "Jack", 86 | LastName = "Black", 87 | HireDate = DB.GetDate(), 88 | UserName = "blackj", 89 | ManagerID = 2, 90 | }; 91 | EmployeeItem empItem = DB.Employees.Insert(emp); // automatically uses the transaction 92 | Console.WriteLine("Manager: " + empItem.Manager.Name + "\nAge: " + empItem.Manager.Age); 93 | transaction.Commit(); 94 | } 95 | } 96 | catch (Exception ex) { 97 | // roll back cache to before the transaction 98 | Console.WriteLine(ex.Message); 99 | Console.WriteLine(ex.StackTrace); 100 | } 101 | // etc... 102 | } 103 | } 104 | } -------------------------------------------------------------------------------- /DapperExtraCRUD.Cache.Example/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("DapperExtraCRUD.Cache.Example")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("DapperExtraCRUD.Cache.Example")] 13 | [assembly: AssemblyCopyright("Copyright © 2020")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("0be78af8-2899-4ec8-a4f2-e4fb33d59b21")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /DapperExtraCRUD.Cache.Example/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /DapperExtraCRUD.Cache/CacheItem.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Released under MIT License 3 | // License: https://opensource.org/licenses/MIT 4 | // Home page: https://github.com/ffhighwind/DapperExtraCRUD 5 | 6 | // Copyright(c) 2018 Wesley Hamilton 7 | 8 | // Permission is hereby granted, free of charge, to any person obtaining a copy 9 | // of this software and associated documentation files (the "Software"), to deal 10 | // in the Software without restriction, including without limitation the rights 11 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the Software is 13 | // furnished to do so, subject to the following conditions: 14 | 15 | // The above copyright notice and this permission notice shall be included in all 16 | // copies or substantial portions of the Software. 17 | 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | // SOFTWARE. 25 | #endregion 26 | 27 | 28 | namespace Dapper.Extra.Cache 29 | { 30 | /// 31 | /// Base class for cached objects. 32 | /// 33 | /// The table type. 34 | public class CacheItem where T : class 35 | { 36 | /// 37 | /// The row value. 38 | /// 39 | protected T cacheValue; 40 | 41 | /// 42 | /// The row value. 43 | /// 44 | public T CacheValue { 45 | get => cacheValue; 46 | protected internal set { 47 | cacheValue = value; 48 | OnValueChanged(); 49 | } 50 | } 51 | 52 | /// 53 | /// Called after is set. This is not called if the row is deleted. 54 | /// 55 | protected virtual void OnValueChanged() 56 | { 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /DapperExtraCRUD.Cache/DapperExtraCRUD.Cache.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | netstandard2.0;netcoreapp2.0;net461 4 | Dapper.ExtraCRUD.Cache 5 | 1.5.4.0 6 | Wesley Hamilton 7 | A Dapper extension that was inspired by Dapper.SimpleCRUD, Dapper-Plus, and more. 8 | en-us 9 | Updated dependency packages. 10 | dapper orm micro-orm sql 11 | Apache-2.0 12 | https://github.com/ffhighwind/DapperExtraCRUD 13 | true 14 | Copyright (c) 2018 Wesley Hamilton 15 | https://github.com/ffhighwind/DapperExtraCRUD 16 | GIT 17 | false 18 | Dapper.Extra.Cache 19 | Apache-2.0 20 | 1.5.4.0 21 | 1.5.4.0 22 | {3059BA7E-5590-4BBC-A38E-1AEDC7D8A8A1} 23 | DapperExtraCRUD-200x200.png 24 | 25 | false 26 | 27 | 28 | 29 | true 30 | full 31 | false 32 | DEBUG;TRACE 33 | prompt 34 | 4 35 | 36 | 37 | 38 | pdbonly 39 | true 40 | TRACE 41 | prompt 42 | 4 43 | bin\lib\ 44 | bin\lib\Dapper.ExtraCRUD.Cache.xml 45 | 46 | 47 | 48 | NETCOREAPP;NETCOREAPP2_0 49 | 50 | 51 | NETSTANDARD;NETSTANDARD2_0 52 | 53 | 54 | NETFRAMEWORK;NET461 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | True 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | -------------------------------------------------------------------------------- /DapperExtraCRUD.Cache/DbCache.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Released under MIT License 3 | // License: https://opensource.org/licenses/MIT 4 | // Home page: https://github.com/ffhighwind/DapperExtraCRUD 5 | 6 | // Copyright(c) 2018 Wesley Hamilton 7 | 8 | // Permission is hereby granted, free of charge, to any person obtaining a copy 9 | // of this software and associated documentation files (the "Software"), to deal 10 | // in the Software without restriction, including without limitation the rights 11 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the Software is 13 | // furnished to do so, subject to the following conditions: 14 | 15 | // The above copyright notice and this permission notice shall be included in all 16 | // copies or substantial portions of the Software. 17 | 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | // SOFTWARE. 25 | #endregion 26 | 27 | using System; 28 | using System.Collections.Generic; 29 | 30 | namespace Dapper.Extra.Cache 31 | { 32 | /// 33 | /// A factory for database caches. 34 | /// 35 | public class DbCache 36 | { 37 | /// 38 | /// A cache of . 39 | /// 40 | private readonly Dictionary Map = new Dictionary(); 41 | 42 | private readonly string ConnectionString; 43 | 44 | /// 45 | /// Initializes a new instance of the class. 46 | /// 47 | /// The connection string 48 | public DbCache(string connectionString) 49 | { 50 | ConnectionString = connectionString; 51 | } 52 | 53 | /// 54 | /// Constructs a that stores the default . 55 | /// 56 | /// The table type. 57 | /// A cache for a database table. 58 | public DbCacheTable> CreateTable() 59 | where T : class 60 | { 61 | return CreateTable>(); 62 | } 63 | 64 | /// 65 | /// Constructs a that stores a specific type. 66 | /// 67 | /// The table type. 68 | /// The type. 69 | /// A cache for a database table. 70 | public DbCacheTable CreateTable() 71 | where T : class 72 | where R : CacheItem, new() 73 | { 74 | DbCacheTable table; 75 | if (Map.TryGetValue(typeof(T), out object obj)) { 76 | table = (DbCacheTable)obj; 77 | } 78 | else { 79 | table = new DbCacheTable(ConnectionString); 80 | Map.Add(typeof(T), table); 81 | } 82 | return table; 83 | } 84 | } 85 | } -------------------------------------------------------------------------------- /DapperExtraCRUD.Cache/DbCacheTransaction.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Released under MIT License 3 | // License: https://opensource.org/licenses/MIT 4 | // Home page: https://github.com/ffhighwind/DapperExtraCRUD 5 | 6 | // Copyright(c) 2018 Wesley Hamilton 7 | 8 | // Permission is hereby granted, free of charge, to any person obtaining a copy 9 | // of this software and associated documentation files (the "Software"), to deal 10 | // in the Software without restriction, including without limitation the rights 11 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the Software is 13 | // furnished to do so, subject to the following conditions: 14 | 15 | // The above copyright notice and this permission notice shall be included in all 16 | // copies or substantial portions of the Software. 17 | 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | // SOFTWARE. 25 | #endregion 26 | 27 | using System; 28 | using System.Collections.Generic; 29 | using System.Data; 30 | using System.Data.SqlClient; 31 | 32 | namespace Dapper.Extra.Cache 33 | { 34 | /// 35 | /// Stores a backup state of all caches in case of a rollback. This has been done efficiently so that it 36 | /// only backs up up modified items in a cache instead of the whole state of the cache. 37 | /// 38 | public class DbCacheTransaction : IDbTransaction 39 | { 40 | internal DbCacheTransaction(IDbTransaction transaction) 41 | { 42 | Transaction = transaction; 43 | } 44 | 45 | internal List TransactionStorage { get; set; } = new List(); 46 | 47 | /// 48 | /// Adds tables to the transaction. 49 | /// 50 | /// The tables to add. 51 | /// The transaction. 52 | public DbCacheTransaction Add(params ICacheTable[] tables) 53 | { 54 | if (Transaction == null) 55 | throw new InvalidOperationException("The transaction is closed."); 56 | foreach (ICacheTable table in tables) { 57 | table.BeginTransaction(this); 58 | } 59 | return this; 60 | } 61 | 62 | internal IDbTransaction Transaction { get; set; } 63 | /// 64 | /// Specifies the Connection object to associate with the transaction. 65 | /// 66 | public IDbConnection Connection => Transaction.Connection; 67 | /// 68 | /// Specifies the for this transaction. 69 | /// 70 | public IsolationLevel IsolationLevel => Transaction.IsolationLevel; 71 | 72 | /// 73 | /// Commits the database transaction. 74 | /// 75 | public void Commit() 76 | { 77 | if (Transaction == null) 78 | return; 79 | Transaction.Commit(); 80 | foreach (IDbTransaction storage in TransactionStorage) { 81 | storage.Commit(); 82 | storage.Dispose(); 83 | } 84 | TransactionStorage.Clear(); 85 | Transaction = null; 86 | } 87 | 88 | /// 89 | /// Rolls back the transaction. 90 | /// 91 | public void Rollback() 92 | { 93 | if (Transaction == null) 94 | return; 95 | foreach (IDbTransaction storage in TransactionStorage) { 96 | storage.Rollback(); 97 | } 98 | Transaction.Rollback(); 99 | } 100 | 101 | #region IDisposable Support 102 | private bool disposedValue = false; // To detect redundant calls 103 | 104 | /// 105 | /// Disposes of the internal and rolls back the caches. 106 | /// 107 | protected virtual void Dispose(bool disposing) 108 | { 109 | if (!disposedValue) { 110 | if (disposing) { 111 | // TODO: dispose managed state (managed objects). 112 | if(Transaction != null) { 113 | IDbConnection connection = Connection; 114 | foreach (IDbTransaction storage in TransactionStorage) { 115 | storage.Dispose(); 116 | } 117 | Transaction.Dispose(); 118 | Transaction = null; 119 | if (connection.State == ConnectionState.Open) 120 | connection.Close(); 121 | } 122 | } 123 | // TODO: free unmanaged resources (unmanaged objects) and override a finalizer below. 124 | // TODO: set large fields to null. 125 | disposedValue = true; 126 | } 127 | } 128 | 129 | // TODO: override a finalizer only if Dispose(bool disposing) above has code to free unmanaged resources. 130 | // ~CacheTransaction() { 131 | // // Do not change this code. Put cleanup code in Dispose(bool disposing) above. 132 | // Dispose(false); 133 | // } 134 | 135 | /// 136 | /// Disposes of the internal and rolls back the caches. 137 | /// 138 | public void Dispose() 139 | { 140 | // This code added to correctly implement the disposable pattern. 141 | // Do not change this code. Put cleanup code in Dispose(bool disposing) above. 142 | Dispose(true); 143 | // TODO: uncomment the following line if the finalizer is overridden above. 144 | // GC.SuppressFinalize(this); 145 | } 146 | #endregion 147 | } 148 | } 149 | -------------------------------------------------------------------------------- /DapperExtraCRUD.Cache/ICacheStorage.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Released under MIT License 3 | // License: https://opensource.org/licenses/MIT 4 | // Home page: https://github.com/ffhighwind/DapperExtraCRUD 5 | 6 | // Copyright(c) 2018 Wesley Hamilton 7 | 8 | // Permission is hereby granted, free of charge, to any person obtaining a copy 9 | // of this software and associated documentation files (the "Software"), to deal 10 | // in the Software without restriction, including without limitation the rights 11 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the Software is 13 | // furnished to do so, subject to the following conditions: 14 | 15 | // The above copyright notice and this permission notice shall be included in all 16 | // copies or substantial portions of the Software. 17 | 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | // SOFTWARE. 25 | #endregion 26 | 27 | using System.Collections.Generic; 28 | 29 | namespace Dapper.Extra.Cache 30 | { 31 | /// 32 | /// The interface for the storage of a . 33 | /// 34 | /// The table type. 35 | /// The cached item type. 36 | public interface ICacheStorage : IDictionary 37 | where T : class 38 | where R : CacheItem, new() 39 | { 40 | /// 41 | /// Adds or updates an object in the storage. 42 | /// 43 | /// The object to add to the storage. 44 | /// The cache item referencing the added object. 45 | R Add(T value); 46 | 47 | /// 48 | /// Adds or updates the objects in the storage. 49 | /// 50 | /// The objects to add to the storage. 51 | /// The cache items referencing the added objects. 52 | List Add(IEnumerable values); 53 | 54 | /// 55 | /// Attempts to remove an object matching a key. 56 | /// 57 | /// The key to remove. 58 | /// True if the object was removed; false otherwise. 59 | bool RemoveKey(object key); 60 | 61 | /// 62 | /// Removes the objects from the storage. 63 | /// 64 | /// The objects to remove. 65 | void Remove(IEnumerable values); 66 | 67 | /// 68 | /// Removes the objects matching the specified keys from the storage. 69 | /// 70 | /// The keys of the objects to remove. 71 | void RemoveKeys(IEnumerable keys); 72 | 73 | /// 74 | /// Removes the objects matching the specified keys from the storage. 75 | /// 76 | /// The keys of the objects to remove. 77 | void RemoveKeys(IEnumerable keys); 78 | 79 | /// 80 | /// Determines whether the storage contains the specified object. 81 | /// 82 | /// The object to locate. 83 | /// True if the object is in the storage; false otherwise. 84 | bool Contains(T value); 85 | 86 | /// 87 | /// Determines whether the storage contains the specified key. 88 | /// 89 | /// The key to locate. 90 | /// True if the key is in the storage; false otherwise. 91 | bool ContainsKey(object key); 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /DapperExtraCRUD.Cache/Internal/CacheAutoStorage.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Released under MIT License 3 | // License: https://opensource.org/licenses/MIT 4 | // Home page: https://github.com/ffhighwind/DapperExtraCRUD 5 | 6 | // Copyright(c) 2018 Wesley Hamilton 7 | 8 | // Permission is hereby granted, free of charge, to any person obtaining a copy 9 | // of this software and associated documentation files (the "Software"), to deal 10 | // in the Software without restriction, including without limitation the rights 11 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the Software is 13 | // furnished to do so, subject to the following conditions: 14 | 15 | // The above copyright notice and this permission notice shall be included in all 16 | // copies or substantial portions of the Software. 17 | 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | // SOFTWARE. 25 | #endregion 26 | 27 | using System; 28 | using System.Collections; 29 | using System.Collections.Generic; 30 | 31 | namespace Dapper.Extra.Cache.Internal 32 | { 33 | internal class CacheAutoStorage : ICacheStorage 34 | where T : class 35 | where R : CacheItem, new() 36 | { 37 | public readonly Dictionary Cache; 38 | 39 | internal CacheAutoStorage() 40 | { 41 | SqlBuilder builder = ExtraCrud.Builder(); 42 | if (builder.Info.KeyColumns.Count == 1) { 43 | ObjectFromKey = builder.ObjectFromKey; 44 | } 45 | Cache = new Dictionary(builder.EqualityComparer); 46 | } 47 | 48 | private Func ObjectFromKey { get; } 49 | 50 | public CacheItem this[T key] => Cache[key]; 51 | 52 | public int Count => Cache.Count; 53 | 54 | ICollection IDictionary.Keys => Cache.Keys; 55 | 56 | ICollection IDictionary.Values => Cache.Values; 57 | 58 | public bool IsReadOnly => false; 59 | 60 | R IDictionary.this[T key] { 61 | get => Cache[key]; 62 | set => Cache[key] = value; 63 | } 64 | 65 | public R Add(T key) 66 | { 67 | if(!Cache.TryGetValue(key, out R item)) { 68 | item = new R(); 69 | Cache.Add(key, item); 70 | } 71 | item.CacheValue = key; 72 | return item; 73 | } 74 | 75 | public List Add(IEnumerable keys) 76 | { 77 | List list = new List(); 78 | foreach (T key in keys) { 79 | R item = Add(key); 80 | list.Add(item); 81 | } 82 | return list; 83 | } 84 | 85 | public bool Remove(T value) 86 | { 87 | bool success = Cache.Remove(value); 88 | return success; 89 | } 90 | 91 | public bool RemoveKey(object key) 92 | { 93 | T obj = ObjectFromKey(key); 94 | bool success = Cache.Remove(obj); 95 | return success; 96 | } 97 | 98 | public void Remove(IEnumerable keys) 99 | { 100 | foreach (T key in keys) { 101 | Remove(key); 102 | } 103 | } 104 | 105 | public void RemoveKeys(IEnumerable keys) 106 | { 107 | foreach (object key in keys) { 108 | RemoveKey(key); 109 | } 110 | } 111 | 112 | public void RemoveKeys(IEnumerable keys) 113 | { 114 | foreach (int key in keys) { 115 | RemoveKey(key); 116 | } 117 | } 118 | 119 | public void Clear() 120 | { 121 | Cache.Clear(); 122 | } 123 | 124 | public bool Contains(T key) 125 | { 126 | bool success = Cache.ContainsKey(key); 127 | return success; 128 | } 129 | 130 | public bool ContainsKey(object key) 131 | { 132 | T obj = ObjectFromKey(key); 133 | bool success = Cache.ContainsKey(obj); 134 | return success; 135 | } 136 | 137 | public bool ContainsKey(T key) 138 | { 139 | bool success = Cache.ContainsKey(key); 140 | return success; 141 | } 142 | 143 | public bool TryGetValue(T key, out R value) 144 | { 145 | bool success = Cache.TryGetValue(key, out value); 146 | return success; 147 | } 148 | 149 | public IEnumerator> GetEnumerator() 150 | { 151 | IEnumerator> enumerator = Cache.GetEnumerator(); 152 | return enumerator; 153 | } 154 | 155 | IEnumerator IEnumerable.GetEnumerator() 156 | { 157 | IEnumerator> enumerator = Cache.GetEnumerator(); 158 | return enumerator; 159 | } 160 | 161 | public void Add(T key, R value) 162 | { 163 | Add(key); 164 | } 165 | 166 | public void Add(KeyValuePair item) 167 | { 168 | ((IDictionary)Cache).Add(item); 169 | } 170 | 171 | public bool Contains(KeyValuePair item) 172 | { 173 | bool success = ((IDictionary)Cache).Contains(item); 174 | return success; 175 | } 176 | 177 | public void CopyTo(KeyValuePair[] array, int arrayIndex) 178 | { 179 | ((IDictionary)Cache).CopyTo(array, arrayIndex); 180 | } 181 | 182 | public bool Remove(KeyValuePair item) 183 | { 184 | bool success = ((IDictionary)Cache).Remove(item); 185 | return success; 186 | } 187 | } 188 | } 189 | -------------------------------------------------------------------------------- /DapperExtraCRUD.Cache/README.md: -------------------------------------------------------------------------------- 1 | # Introduction 2 | 3 | [Nuget: Dapper.ExtraCRUD.Cache](https://www.nuget.org/packages/Dapper.ExtraCRUD.Cache/) 4 | ExtraCRUD 5 | 6 | A cache framework for Dapper.ExtraCRUD. This combines the an AutoAccessObject, DataAccessObject, and Dictionary together with support for transactions and rollbacks. The cache is not thread-safe. Make sure to keep a separate cache for each thread. 7 | 8 | ## Example 9 | 10 | ```csharp 11 | using System; 12 | using System.Data.SqlClient; 13 | using Dapper.Extra.Annotations; 14 | using Dapper.Extra.Cache; 15 | using Dapper; 16 | 17 | namespace Example 18 | { 19 | [Table("Employees")] 20 | public class Employee 21 | { 22 | [Key] 23 | public int EmployeeID { get; set; } 24 | public string UserName { get; set; } 25 | public string FirstName { get; set; } 26 | public string LastName { get; set; } 27 | public DateTime HireDate { get; set; } 28 | public int ManagerID { get; set; } 29 | public DateTime DateOfBirth { get; set; } 30 | [IgnoreInsert("getdate()")] 31 | [MatchUpdate("getdate()")] 32 | [AutoSync(syncInsert: true, syncUpdate: true)] 33 | public DateTime ModifiedDate { get; set; } 34 | [IgnoreInsert("getdate()", true)] 35 | [IgnoreUpdate] 36 | public DateTime CreatedDate { get; set; } 37 | } 38 | 39 | public class EmployeeItem : CacheItem 40 | { 41 | public int ID => CacheValue.EmployeeID; 42 | public string UserName => CacheValue.UserName; 43 | public string Name => CacheValue.FirstName + " " + CacheValue.LastName; 44 | public DateTime HireDate => CacheValue.HireDate; 45 | public EmployeeItem Manager => LazyManager.Value; 46 | public DateTime DOB => CacheValue.DateOfBirth; 47 | public double Age => (DateTime.Today - CacheValue.DateOfBirth).TotalDays / 365.0; 48 | public DateTime ModifiedDate => CacheValue.ModifiedDate; 49 | public DateTime CreatedDate => CacheValue.CreatedDate; 50 | private Lazy LazyManager; 51 | protected override void OnValueChanged() 52 | { 53 | // Lazy is required here or this could be costly 54 | LazyManager = new Lazy(() => DB.Employees[CacheValue.ManagerID], false); 55 | } 56 | 57 | public bool Save() 58 | { 59 | // Returns false if deleted or the row was not modified 60 | return DB.Employees.Update(CacheValue); 61 | } 62 | 63 | public bool Load() 64 | { 65 | EmployeeItem value = DB.Employees.Get(CacheValue); 66 | return value == this; 67 | } 68 | } 69 | 70 | public static class DB 71 | { 72 | private const string ConnString = "Server=myServerAddress;Database=myDataBase;User Id=myUsername;Password=myPassword;"; 73 | private static readonly DbCache Cache = new DbCache(ConnString); 74 | public static readonly DbCacheTable Employees = Cache.CreateTable(); 75 | 76 | public static DateTime GetDate() 77 | { 78 | using (SqlConnection conn = new SqlConnection(ConnString)) { 79 | // getdate() could be replaced by SqlAdapter.CurrentDateTime 80 | return conn.QueryFirst("select getdate()"); 81 | } 82 | } 83 | } 84 | 85 | public static class Program 86 | { 87 | public static void Main() 88 | { 89 | DB.Employees.GetList(); // caches all employees in the database 90 | 91 | try { 92 | using (DbCacheTransaction transaction = DB.Employees.BeginTransaction()) { 93 | Employee emp = new Employee() { 94 | DateOfBirth = new DateTime(2000, 2, 15), 95 | FirstName = "Jack", 96 | LastName = "Black", 97 | HireDate = DB.GetDate(), 98 | UserName = "blackj", 99 | ManagerID = 2, 100 | }; 101 | EmployeeItem empItem = DB.Employees.Insert(emp); // automatically uses the transaction 102 | Console.WriteLine("Manager: " + empItem.Manager.Name + "\nAge: " + empItem.Manager.Age); 103 | transaction.Commit(); 104 | } 105 | } 106 | catch (Exception ex) { 107 | // roll back cache to before the transaction 108 | Console.WriteLine(ex.Message); 109 | Console.WriteLine(ex.StackTrace); 110 | } 111 | // etc... 112 | } 113 | } 114 | } 115 | ``` 116 | # License: 117 | 118 | *MIT License* 119 | 120 | Copyright (c) 2018 Wesley Hamilton 121 | 122 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 123 | 124 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 125 | -------------------------------------------------------------------------------- /DapperExtraCRUD.Example/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /DapperExtraCRUD.Example/BulkOptionsAdapter.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Released under MIT License 3 | // License: https://opensource.org/licenses/MIT 4 | // Home page: https://github.com/ffhighwind/DapperExtraCRUD 5 | 6 | // Copyright(c) 2018 Wesley Hamilton 7 | 8 | // Permission is hereby granted, free of charge, to any person obtaining a copy 9 | // of this software and associated documentation files (the "Software"), to deal 10 | // in the Software without restriction, including without limitation the rights 11 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the Software is 13 | // furnished to do so, subject to the following conditions: 14 | 15 | // The above copyright notice and this permission notice shall be included in all 16 | // copies or substantial portions of the Software. 17 | 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | // SOFTWARE. 25 | #endregion 26 | 27 | using System; 28 | using System.Collections.Generic; 29 | using System.Data; 30 | using System.Data.SqlClient; 31 | using Fasterflect; 32 | 33 | namespace Dapper.Extra.Adapters 34 | { 35 | /// 36 | /// An that changes the default behavior of bulk SQL commands. 37 | /// 38 | public class BulkOptionsAdapter : ISqlAdapter 39 | { 40 | private readonly ISqlAdapter Adapter; 41 | 42 | private readonly SqlBulkCopyOptions OptionsMask; 43 | 44 | /// 45 | /// Constructs an that changes the default behavior of bulk SQL commands. 46 | /// 47 | /// The adapter to copy. By default this is the SQL Server adapter. 48 | /// The mask that limits the options 49 | /// allowed for all bulk operations. By default this prevents triggers from being fired. 50 | public BulkOptionsAdapter(ISqlAdapter adapter = null, SqlBulkCopyOptions optionsMask = ~SqlBulkCopyOptions.FireTriggers) 51 | { 52 | Adapter = adapter ?? SqlAdapter.SQLServer; 53 | OptionsMask = optionsMask; 54 | } 55 | 56 | public string LimitQuery => Adapter.LimitQuery; 57 | 58 | public SqlDialect Dialect => Adapter.Dialect; 59 | 60 | public string CurrentDate => Adapter.CurrentDate; 61 | 62 | public string CurrentDateTime => Adapter.CurrentDateTime; 63 | 64 | public string CurrentDateTimeUtc => Adapter.CurrentDateTimeUtc; 65 | 66 | public string CurrentDateUtc => Adapter.CurrentDateUtc; 67 | 68 | public IEqualityComparer StringComparer => Adapter.StringComparer; 69 | 70 | public void BulkInsert(IDbConnection connection, IEnumerable objs, IDbTransaction transaction, string tableName, DataReaderFactory factory, IEnumerable columns, int commandTimeout = 30, SqlBulkCopyOptions options = SqlBulkCopyOptions.Default) where T : class 71 | { 72 | Adapter.BulkInsert(connection, objs, transaction, tableName, factory, columns, commandTimeout, options & OptionsMask); 73 | } 74 | 75 | public string CreateTempTableName(string tableName) 76 | { 77 | return Adapter.CreateTempTableName(tableName); 78 | } 79 | 80 | public string DropTempTableIfExists(string tableName) 81 | { 82 | return Adapter.DropTempTableIfExists(tableName); 83 | } 84 | 85 | public string QuoteIdentifier(string identifier) 86 | { 87 | return Adapter.QuoteIdentifier(identifier); 88 | } 89 | 90 | public string SelectIdentityQuery(Type type) 91 | { 92 | return Adapter.SelectIdentityQuery(type); 93 | } 94 | 95 | public string SelectIntoTempTable(string sourceTable, string tempTable, IEnumerable columns) 96 | { 97 | return Adapter.SelectIntoTempTable(sourceTable, tempTable, columns); 98 | } 99 | 100 | public string TruncateTable(string tableName) 101 | { 102 | return Adapter.TruncateTable(tableName); 103 | } 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /DapperExtraCRUD.Example/CollateAdapter.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Released under MIT License 3 | // License: https://opensource.org/licenses/MIT 4 | // Home page: https://github.com/ffhighwind/DapperExtraCRUD 5 | 6 | // Copyright(c) 2018 Wesley Hamilton 7 | 8 | // Permission is hereby granted, free of charge, to any person obtaining a copy 9 | // of this software and associated documentation files (the "Software"), to deal 10 | // in the Software without restriction, including without limitation the rights 11 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the Software is 13 | // furnished to do so, subject to the following conditions: 14 | 15 | // The above copyright notice and this permission notice shall be included in all 16 | // copies or substantial portions of the Software. 17 | 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | // SOFTWARE. 25 | #endregion 26 | 27 | using System; 28 | using System.Collections.Generic; 29 | using System.Data; 30 | using System.Data.SqlClient; 31 | using Fasterflect; 32 | 33 | namespace Dapper.Extra.Adapters 34 | { 35 | /// 36 | /// An that changes the string comparison for generated by . 37 | /// 38 | public class CollateAdapter : ISqlAdapter 39 | { 40 | private readonly ISqlAdapter Adapter; 41 | 42 | /// 43 | /// Constructs An that changes the string comparison for generated by . 44 | /// 45 | /// The comparer for strings comparisons. This is (case-sensitive) if null. 46 | public CollateAdapter(IEqualityComparer stringComparer) : this(null, stringComparer) 47 | { 48 | } 49 | 50 | /// 51 | /// Constructs An that changes the string comparison for generated by . 52 | /// 53 | /// The adapter to copy. By default this is the SQL Server adapter. 54 | /// The comparer for strings comparisons. By default this is (case-sensitive). 55 | public CollateAdapter(ISqlAdapter adapter, IEqualityComparer stringComparer = null) 56 | { 57 | Adapter = adapter ?? SqlAdapter.SQLServer; 58 | StringComparer = stringComparer ?? System.StringComparer.Ordinal; 59 | } 60 | 61 | public string LimitQuery => Adapter.LimitQuery; 62 | 63 | public SqlDialect Dialect => Adapter.Dialect; 64 | 65 | public string CurrentDate => Adapter.CurrentDate; 66 | 67 | public string CurrentDateTime => Adapter.CurrentDateTime; 68 | 69 | public string CurrentDateTimeUtc => Adapter.CurrentDateTimeUtc; 70 | 71 | public string CurrentDateUtc => Adapter.CurrentDateUtc; 72 | 73 | public IEqualityComparer StringComparer { get; private set; } 74 | 75 | public void BulkInsert(IDbConnection connection, IEnumerable objs, IDbTransaction transaction, string tableName, DataReaderFactory factory, IEnumerable columns, int commandTimeout = 30, SqlBulkCopyOptions options = SqlBulkCopyOptions.Default) where T : class 76 | { 77 | Adapter.BulkInsert(connection, objs, transaction, tableName, factory, columns, commandTimeout, options); 78 | } 79 | 80 | public string CreateTempTableName(string tableName) 81 | { 82 | return Adapter.CreateTempTableName(tableName); 83 | } 84 | 85 | public string DropTempTableIfExists(string tableName) 86 | { 87 | return Adapter.DropTempTableIfExists(tableName); 88 | } 89 | 90 | public string QuoteIdentifier(string identifier) 91 | { 92 | return Adapter.QuoteIdentifier(identifier); 93 | } 94 | 95 | public string SelectIdentityQuery(Type type) 96 | { 97 | return Adapter.SelectIdentityQuery(type); 98 | } 99 | 100 | public string SelectIntoTempTable(string sourceTable, string tempTable, IEnumerable columns) 101 | { 102 | return Adapter.SelectIntoTempTable(sourceTable, tempTable, columns); 103 | } 104 | 105 | public string TruncateTable(string tableName) 106 | { 107 | return Adapter.TruncateTable(tableName); 108 | } 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /DapperExtraCRUD.Example/DapperExtraCRUD.Example.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {93F2BF4E-152A-4C72-A3D7-96F1C7AE2E05} 8 | Exe 9 | DapperExtraCRUD.Example 10 | DapperExtraCRUD.Example 11 | v4.6.1 12 | 512 13 | true 14 | true 15 | 16 | 17 | AnyCPU 18 | true 19 | full 20 | false 21 | bin\Debug\ 22 | DEBUG;TRACE 23 | prompt 24 | 4 25 | 26 | 27 | AnyCPU 28 | pdbonly 29 | true 30 | bin\Release\ 31 | TRACE 32 | prompt 33 | 4 34 | 35 | 36 | 37 | ..\packages\Dapper.StrongName.2.0.30\lib\net461\Dapper.StrongName.dll 38 | 39 | 40 | ..\packages\Fasterflect.Reflect.3.1.0\lib\net45\Fasterflect.Reflect.dll 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | {4DBE71C1-2ECD-4192-BC66-E4D1C8DCEC08} 66 | DapperExtraCRUD 67 | 68 | 69 | 70 | -------------------------------------------------------------------------------- /DapperExtraCRUD.Example/DapperExtraCRUD.Example.csproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | ProjectFiles 5 | 6 | -------------------------------------------------------------------------------- /DapperExtraCRUD.Example/Program.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Released under MIT License 3 | // License: https://opensource.org/licenses/MIT 4 | // Home page: https://github.com/ffhighwind/DapperExtraCRUD 5 | 6 | // Copyright(c) 2018 Wesley Hamilton 7 | 8 | // Permission is hereby granted, free of charge, to any person obtaining a copy 9 | // of this software and associated documentation files (the "Software"), to deal 10 | // in the Software without restriction, including without limitation the rights 11 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the Software is 13 | // furnished to do so, subject to the following conditions: 14 | 15 | // The above copyright notice and this permission notice shall be included in all 16 | // copies or substantial portions of the Software. 17 | 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | // SOFTWARE. 25 | #endregion 26 | 27 | using System; 28 | using System.Collections.Generic; 29 | using System.Data.SqlClient; 30 | using System.Linq; 31 | using Dapper; 32 | using Dapper.Extra.Utilities; 33 | 34 | namespace DapperExtraCRUD.Example 35 | { 36 | public static class Program 37 | { 38 | private const string ConnString = "Server=myServerAddress;Database=myDataBase;User Id=myUsername;Password=myPassword;"; 39 | 40 | public static void Main() 41 | { 42 | using (SqlConnection conn = new SqlConnection(ConnString)) { 43 | DateTime minHireDate = DateTime.Today.AddDays(-30); 44 | IEnumerable users = conn.GetList("where HireDate >= @minHireDate ", new { minHireDate }); 45 | User user = new User() { 46 | FirstName = "Jason", 47 | LastName = "Borne", 48 | UserName = "jborne", 49 | Permissions = UserPermissions.Admin, 50 | }; 51 | conn.Insert(user); 52 | 53 | string condition = WhereConditionGenerator.Create((u) => u.UserName == "jborne" 54 | && (u.FirstName != null || u.Permissions == UserPermissions.Basic) 55 | && new string[] { "Jason", "Chris", "Zack" }.Contains(u.FirstName), 56 | out IDictionary param); 57 | // condition = "(((Test.Col1 = 11) AND ((Test.Col2 is not NULL) OR (Test.Col4 is NULL))) AND Test.Col2 in @P0)" 58 | // param = List() { "aa", "bb", "cc" } 59 | IEnumerable result4 = conn.Query("SELECT * FROM Users WHERE " + condition, param); 60 | } 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /DapperExtraCRUD.Example/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("DapperExtraCRUD.Example")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("DapperExtraCRUD.Example")] 13 | [assembly: AssemblyCopyright("Copyright © 2020")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("93f2bf4e-152a-4c72-a3d7-96f1c7ae2e05")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /DapperExtraCRUD.Example/User.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Dapper.Extra.Annotations; 3 | 4 | namespace DapperExtraCRUD.Example 5 | { 6 | [IgnoreDelete] 7 | [Table(name: "Users", declaredOnly: true, inheritAttrs: true)] 8 | public class User 9 | { 10 | [Key] 11 | public int UserID { get; private set; } 12 | 13 | public string FirstName { get; set; } 14 | 15 | public string LastName { get; set; } 16 | 17 | [Column("Account Name")] 18 | public string UserName { get; set; } 19 | 20 | public UserPermissions Permissions { get; set; } 21 | 22 | [IgnoreInsert(value: null, autoSync: true)] 23 | [MatchUpdate(value: "getdate()", autoSync: true)] 24 | [MatchDelete] 25 | public DateTime Modified { get; protected set; } 26 | 27 | [IgnoreUpdate] 28 | [IgnoreInsert("getdate()")] 29 | public DateTime Created { get; private set; } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /DapperExtraCRUD.Example/UserPermissions.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace DapperExtraCRUD.Example 3 | { 4 | public enum UserPermissions 5 | { 6 | None = 0, 7 | Basic, 8 | Admin, 9 | SuperAdmin, 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /DapperExtraCRUD.Example/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /DapperExtraCRUD/DapperExtraCRUD.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | netstandard2.0;netcoreapp2.0;net461 4 | Dapper.ExtraCRUD 5 | 1.5.4.0 6 | Wesley Hamilton 7 | A Dapper extension that was inspired by Dapper.SimpleCRUD, Dapper-Plus, and more. 8 | en-us 9 | Updated ExtraCrud.IsValidType to support TypeHandlers better as suggested by a user. 10 | dapper orm micro-orm sql 11 | MIT 12 | https://github.com/ffhighwind/DapperExtraCRUD 13 | true 14 | Copyright (c) 2018 Wesley Hamilton 15 | https://github.com/ffhighwind/DapperExtraCRUD 16 | GIT 17 | false 18 | Dapper 19 | MIT 20 | 1.5.4.0 21 | 1.5.4.0 22 | {4DBE71C1-2ECD-4192-BC66-E4D1C8DCEC08} 23 | true 24 | key.snk 25 | DapperExtraCRUD-200x200.png 26 | 27 | 28 | 29 | 30 | true 31 | full 32 | false 33 | DEBUG;TRACE 34 | prompt 35 | 4 36 | 37 | 38 | 39 | pdbonly 40 | true 41 | TRACE 42 | prompt 43 | 4 44 | bin\lib\ 45 | bin\lib\Dapper.ExtraCRUD.xml 46 | 47 | 48 | 49 | NETCOREAPP;NETCOREAPP2_0 50 | 51 | 52 | NETSTANDARD;NETSTANDARD2_0 53 | 54 | 55 | NETFRAMEWORK;NET461 56 | 57 | 58 | 59 | 60 | 61 | 62 | True 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | -------------------------------------------------------------------------------- /DapperExtraCRUD/DapperExtraCRUD.csproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | ProjectFiles 5 | false 6 | 7 | -------------------------------------------------------------------------------- /DapperExtraCRUD/Extra/Adapters/MySqlAdapter.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Released under MIT License 3 | // License: https://opensource.org/licenses/MIT 4 | // Home page: https://github.com/ffhighwind/DapperExtraCRUD 5 | 6 | // Copyright(c) 2018 Wesley Hamilton 7 | 8 | // Permission is hereby granted, free of charge, to any person obtaining a copy 9 | // of this software and associated documentation files (the "Software"), to deal 10 | // in the Software without restriction, including without limitation the rights 11 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the Software is 13 | // furnished to do so, subject to the following conditions: 14 | 15 | // The above copyright notice and this permission notice shall be included in all 16 | // copies or substantial portions of the Software. 17 | 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | // SOFTWARE. 25 | #endregion 26 | 27 | using System; 28 | 29 | namespace Dapper.Extra.Internal.Adapters 30 | { 31 | /// 32 | /// An that generates SQL commands for MySQL. 33 | /// 34 | internal class MySqlAdapter : SqlAdapterImpl 35 | { 36 | /// 37 | /// An that generates SQL commands for MySQL. 38 | /// 39 | internal MySqlAdapter() : base(SqlDialect.MySQL) 40 | { 41 | QuoteLeft = "`"; 42 | QuoteRight = "`"; 43 | EscapeQuote = "``"; 44 | SelectIntIdentityQuery = "SELECT LAST_INSERT_ID() as `Id`;"; 45 | DropTempTableIfExistsQuery = "DROP TEMPORARY TABLE IF EXISTS {0};"; 46 | TruncateTableQuery = "TRUNCATE TABLE {0};"; 47 | CreateTempTable = @"CREATE TEMPORARY TABLE {0} 48 | "; 49 | TempTableName = "_{0}"; 50 | LimitQuery = @"{1} 51 | LIMIT {0}"; 52 | 53 | CurrentDate = "CURDATE()"; 54 | CurrentDateTime = "NOW()"; 55 | CurrentDateUtc = "CAST(UTC_TIMESTAMP() as DATE)"; 56 | CurrentDateTimeUtc = "UTC_TIMESTAMP()"; 57 | } 58 | 59 | //public override void BulkInsert(IDbConnection connection, IEnumerable objs, IDbTransaction transaction, string tableName, DataReaderFactory factory, 60 | // IEnumerable columns, int commandTimeout = 30, SqlBulkCopyOptions options = SqlBulkCopyOptions.Default) 61 | //{ 62 | // https://dev.mysql.com/doc/refman/8.0/en/load-data.html 63 | // @"C:\Program Files (x86)\MySQL\MySQL Server 5.0\bin\mysql.exe", 64 | // LOAD DATA INFILE 'file.txt' INTO TABLE table; 65 | // FIELDS TERMINATED BY '\t' ENCLOSED BY '' ESCAPED BY '\\' 66 | // LINES TERMINATED BY '\n' STARTING BY '' 67 | //} 68 | 69 | /* 70 | /// 71 | /// Creates an SQL command to call the DATEADD function. 72 | /// 73 | /// The interval type 74 | /// The amount to add. 75 | /// The datetime column. If this is null then it will be replaced by the current date. 76 | /// A command to call the DATEADD function. 77 | public override string DateAdd(TimeInterval interval, int amount, SqlColumn column = null) 78 | { 79 | string intervalStr; 80 | switch (interval) { 81 | case TimeInterval.MILLISECOND: 82 | amount *= 1000; 83 | goto case TimeInterval.MICROSECOND; 84 | case TimeInterval.MICROSECOND: 85 | intervalStr = "MICROSECOND"; 86 | break; 87 | case TimeInterval.SECOND: 88 | intervalStr = "SECOND"; 89 | break; 90 | case TimeInterval.MINUTE: 91 | intervalStr = "MINUTE"; 92 | break; 93 | case TimeInterval.HOUR: 94 | intervalStr = "HOUR"; 95 | break; 96 | case TimeInterval.DAY: 97 | intervalStr = "DAY"; 98 | break; 99 | case TimeInterval.WEEK: 100 | intervalStr = "WEEK"; 101 | break; 102 | case TimeInterval.MONTH: 103 | intervalStr = "MONTH"; 104 | break; 105 | case TimeInterval.QUARTER: 106 | intervalStr = "QUARTER"; 107 | break; 108 | case TimeInterval.YEAR: 109 | intervalStr = "YEAR"; 110 | break; 111 | default: 112 | throw new InvalidOperationException(interval.ToString()); 113 | } 114 | string columnStr = column == null ? "@" + column.ColumnName : CurrDateTime; 115 | return string.Format("DATE_ADD({0}, INTERVAL {1} {2})", columnStr, intervalStr, amount); 116 | } 117 | */ 118 | } 119 | } 120 | -------------------------------------------------------------------------------- /DapperExtraCRUD/Extra/Adapters/OracleAdapter.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Released under MIT License 3 | // License: https://opensource.org/licenses/MIT 4 | // Home page: https://github.com/ffhighwind/DapperExtraCRUD 5 | 6 | // Copyright(c) 2018 Wesley Hamilton 7 | 8 | // Permission is hereby granted, free of charge, to any person obtaining a copy 9 | // of this software and associated documentation files (the "Software"), to deal 10 | // in the Software without restriction, including without limitation the rights 11 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the Software is 13 | // furnished to do so, subject to the following conditions: 14 | 15 | // The above copyright notice and this permission notice shall be included in all 16 | // copies or substantial portions of the Software. 17 | 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | // SOFTWARE. 25 | #endregion 26 | 27 | namespace Dapper.Extra.Internal.Adapters 28 | { 29 | /// 30 | /// An that generates SQL commands for Oracle. 31 | /// 32 | internal class OracleAdapter : SqlAdapterImpl 33 | { 34 | /// 35 | /// Initializes a new instance of the class. 36 | /// 37 | public OracleAdapter() : base(SqlDialect.Oracle) 38 | { 39 | QuoteLeft = "'"; 40 | QuoteRight = "'"; 41 | EscapeQuoteRight = "''"; 42 | SelectIntIdentityQuery = ""; // SEQUENCE? 43 | DropTableIfExistsQuery = @" 44 | BEGIN 45 | EXECUTE IMMEDIATE 'DROP TABLE {0}'; 46 | EXCEPTION 47 | WHEN OTHERS THEN NULL; 48 | END;"; 49 | TruncateTableQuery = "TRUNCATE TABLE {0};"; 50 | TempTableName = "{0}"; 51 | CreateTempTable = ""; 52 | LimitQuery = @"TOP({0}) 53 | {1}"; 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /DapperExtraCRUD/Extra/Adapters/PostgreSqlAdapter.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Released under MIT License 3 | // License: https://opensource.org/licenses/MIT 4 | // Home page: https://github.com/ffhighwind/DapperExtraCRUD 5 | 6 | // Copyright(c) 2018 Wesley Hamilton 7 | 8 | // Permission is hereby granted, free of charge, to any person obtaining a copy 9 | // of this software and associated documentation files (the "Software"), to deal 10 | // in the Software without restriction, including without limitation the rights 11 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the Software is 13 | // furnished to do so, subject to the following conditions: 14 | 15 | // The above copyright notice and this permission notice shall be included in all 16 | // copies or substantial portions of the Software. 17 | 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | // SOFTWARE. 25 | #endregion 26 | 27 | using System; 28 | 29 | namespace Dapper.Extra.Internal.Adapters 30 | { 31 | /// 32 | /// An that generates SQL commands for PostgreSQL. 33 | /// 34 | internal class PostgreSqlAdapter : SqlAdapterImpl 35 | { 36 | /// 37 | /// Initializes a new instance of the class. 38 | /// 39 | internal PostgreSqlAdapter() : base(SqlDialect.PostgreSQL) 40 | { 41 | QuoteLeft = "\""; 42 | QuoteRight = "\""; 43 | EscapeQuote = "\"\""; 44 | SelectIntIdentityQuery = "SELECT LASTVAL() as \"Id\";"; 45 | DropTempTableIfExistsQuery = "DROP TEMPORARY TABLE IF EXISTS {0};"; 46 | TruncateTableQuery = "TRUNCATE TABLE ONLY {0};"; 47 | CreateTempTable = @"CREATE TEMPORARY TABLE {0} AS 48 | "; 49 | TempTableName = "_{0}"; 50 | LimitQuery = @"{1} 51 | LIMIT {0}"; 52 | CurrentDate = "CURRENT_DATE"; 53 | CurrentDateTime = "NOW()"; 54 | CurrentDateUtc = "(CURRENT_DATE AT TIME ZONE 'UTC')"; 55 | CurrentDateTimeUtc = "(NOW() AT TIME ZONE 'UTC')"; 56 | } 57 | 58 | //public override void BulkInsert(IDbConnection connection, IEnumerable objs, IDbTransaction transaction, string tableName, DataReaderFactory factory, 59 | // IEnumerable columns, int commandTimeout = 30, SqlBulkCopyOptions options = SqlBulkCopyOptions.Default) 60 | //{ 61 | // https://www.postgresql.org/docs/9.1/sql-copy.html 62 | // COPY table FROM file [CSV|BINARY] 63 | // COPY [BINARY] table FROM file 64 | //} 65 | 66 | /* 67 | /// 68 | /// Creates an SQL command to call the DATEADD function. 69 | /// 70 | /// The interval type 71 | /// The amount to add. 72 | /// The datetime column. If this is null then it will be replaced by the current date. 73 | /// A command to call the DATEADD function. 74 | public override string DateAdd(TimeInterval interval, int amount, SqlColumn column = null) 75 | { 76 | string opStr = amount < 0 ? "-" : "+"; 77 | string intervalStr; 78 | switch (interval) { 79 | case TimeInterval.MICROSECOND: 80 | amount /= 1000; 81 | goto case TimeInterval.MILLISECOND; 82 | case TimeInterval.MILLISECOND: 83 | intervalStr = new TimeSpan(0, 0, 0, amount).ToString("'hh:mm:ss.fff'"); 84 | break; 85 | case TimeInterval.SECOND: 86 | intervalStr = amount + " SECONDS"; 87 | break; 88 | case TimeInterval.MINUTE: 89 | intervalStr = amount + " MINUTES"; 90 | break; 91 | case TimeInterval.HOUR: 92 | intervalStr = amount + " HOURS"; 93 | break; 94 | case TimeInterval.DAY: 95 | intervalStr = amount + " DAYS"; 96 | break; 97 | case TimeInterval.WEEK: 98 | amount *= 7; 99 | intervalStr = amount + " DAYS"; 100 | break; 101 | case TimeInterval.MONTH: 102 | intervalStr = amount + " MONTHS"; 103 | break; 104 | case TimeInterval.QUARTER: 105 | intervalStr = amount + " MONTHS"; 106 | break; 107 | case TimeInterval.YEAR: 108 | intervalStr = amount + " YEARS"; 109 | break; 110 | default: 111 | throw new InvalidOperationException(interval.ToString()); 112 | } 113 | string columnStr = column == null ? "@" + column.ColumnName : CurrDateTime; 114 | return string.Format("({0} {1} INTERVAL {2}))", columnStr, opStr, intervalStr); 115 | } 116 | */ 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /DapperExtraCRUD/Extra/Adapters/SqlLiteAdapter.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Released under MIT License 3 | // License: https://opensource.org/licenses/MIT 4 | // Home page: https://github.com/ffhighwind/DapperExtraCRUD 5 | 6 | // Copyright(c) 2018 Wesley Hamilton 7 | 8 | // Permission is hereby granted, free of charge, to any person obtaining a copy 9 | // of this software and associated documentation files (the "Software"), to deal 10 | // in the Software without restriction, including without limitation the rights 11 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the Software is 13 | // furnished to do so, subject to the following conditions: 14 | 15 | // The above copyright notice and this permission notice shall be included in all 16 | // copies or substantial portions of the Software. 17 | 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | // SOFTWARE. 25 | #endregion 26 | 27 | using System; 28 | 29 | namespace Dapper.Extra.Internal.Adapters 30 | { 31 | /// 32 | /// An that generates SQL commands for Sqlite. 33 | /// 34 | internal class SqlLiteAdapter : SqlAdapterImpl 35 | { 36 | /// 37 | /// Initializes a new instance of the class. 38 | /// 39 | internal SqlLiteAdapter() : base(SqlDialect.SQLite) 40 | { 41 | QuoteLeft = "\""; 42 | QuoteRight = "\""; 43 | EscapeQuote = "\"\""; 44 | SelectIntIdentityQuery = "SELECT LAST_INSERT_ROWID() as \"Id\";"; 45 | DropTempTableIfExistsQuery = "DROP TABLE IF EXISTS {0};"; 46 | TruncateTableQuery = @"DELETE FROM {0}; 47 | DELETE FROM SQLITE_SEQUENCE WHERE name='{0}'"; // resets autoincrement 48 | CreateTempTable = @"CREATE TEMPORARY TABLE {0} AS 49 | "; 50 | TempTableName = "_{0}"; // temp.{0} 51 | LimitQuery = @"{1} 52 | LIMIT {0}"; 53 | CurrentDate = "DATE('now', 'localtime')"; 54 | CurrentDateTime = "DATETIME('now', 'localtime')"; 55 | CurrentDateUtc = "DATE('now')"; 56 | CurrentDateTimeUtc = "DATETIME('now')"; 57 | } 58 | 59 | //public override void BulkInsert(IDbConnection connection, IEnumerable objs, IDbTransaction transaction, string tableName, DataReaderFactory factory, 60 | // IEnumerable columns, int commandTimeout = 30, SqlBulkCopyOptions options = SqlBulkCopyOptions.Default) 61 | //{ 62 | // EXEC sqlite3.exe csvfile table 63 | //} 64 | 65 | /* 66 | /// 67 | /// Creates an SQL command to call the DATEADD function. 68 | /// 69 | /// The interval type 70 | /// The amount to add. 71 | /// The datetime column. If this is null then it will be replaced by the current date. 72 | /// A command to call the DATEADD function. 73 | public override string DateAdd(TimeInterval interval, int amount, SqlColumn column = null) 74 | { 75 | object amountObj = amount; 76 | string addSubStr = amount < 0 ? "-" : "+"; 77 | string columnStr = column == null ? "@" + column.ColumnName : "'localtime'"; 78 | string intervalStr; 79 | switch (interval) { 80 | case TimeInterval.MICROSECOND: 81 | amountObj = (amount / 1000000.0).ToString("0.0#####"); 82 | intervalStr = "second"; 83 | break; 84 | case TimeInterval.MILLISECOND: 85 | amountObj = (amount / 1000000.0).ToString("0.0##"); 86 | intervalStr = "second"; 87 | break; 88 | case TimeInterval.SECOND: 89 | intervalStr = "second"; 90 | break; 91 | case TimeInterval.MINUTE: 92 | intervalStr = "minute"; 93 | break; 94 | case TimeInterval.HOUR: 95 | intervalStr = "hour"; 96 | break; 97 | case TimeInterval.WEEK: 98 | amountObj = amount * 7; 99 | intervalStr = "day"; 100 | break; 101 | case TimeInterval.DAY: 102 | intervalStr = "day"; 103 | break; 104 | case TimeInterval.QUARTER: 105 | amountObj = amount * 3; 106 | intervalStr = "month"; 107 | break; 108 | case TimeInterval.MONTH: 109 | intervalStr = "month"; 110 | break; 111 | case TimeInterval.YEAR: 112 | intervalStr = "year"; 113 | break; 114 | default: 115 | throw new InvalidOperationException(interval.ToString()); 116 | } 117 | return string.Format("DATETIME({0}, {1}{2} {3})", columnStr, addSubStr, intervalStr, amountObj); 118 | } 119 | */ 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /DapperExtraCRUD/Extra/Annotations/AutoSyncAttribute.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Released under MIT License 3 | // License: https://opensource.org/licenses/MIT 4 | // Home page: https://github.com/ffhighwind/DapperExtraCRUD 5 | 6 | // Copyright(c) 2018 Wesley Hamilton 7 | 8 | // Permission is hereby granted, free of charge, to any person obtaining a copy 9 | // of this software and associated documentation files (the "Software"), to deal 10 | // in the Software without restriction, including without limitation the rights 11 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the Software is 13 | // furnished to do so, subject to the following conditions: 14 | 15 | // The above copyright notice and this permission notice shall be included in all 16 | // copies or substantial portions of the Software. 17 | 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | // SOFTWARE. 25 | #endregion License 26 | 27 | using System; 28 | 29 | namespace Dapper.Extra.Annotations 30 | { 31 | /// 32 | /// Synchronizes the column with the database on updates/inserts. 33 | /// 34 | [AttributeUsage(AttributeTargets.Property | AttributeTargets.Class, AllowMultiple = false, Inherited = true)] 35 | public class AutoSyncAttribute : Attribute 36 | { 37 | /// 38 | /// Initializes a new instance of the attribute. 39 | /// 40 | /// Determines if this column will be automatically selected after an insert. 41 | /// Determines if this column will be automatically selected after an update. 42 | public AutoSyncAttribute(bool syncInsert = true, bool syncUpdate = true) 43 | { 44 | SyncInsert = syncInsert; 45 | SyncUpdate = syncUpdate; 46 | } 47 | 48 | /// 49 | /// Determines if this column will be automatically selected after an insert. 50 | /// 51 | public bool SyncInsert { get; } 52 | 53 | /// 54 | /// Determines if this column will be automatically selected after an update. 55 | /// 56 | public bool SyncUpdate { get; } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /DapperExtraCRUD/Extra/Annotations/ColumnAttribute.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Released under MIT License 3 | // License: https://opensource.org/licenses/MIT 4 | // Home page: https://github.com/ffhighwind/DapperExtraCRUD 5 | 6 | // Copyright(c) 2018 Wesley Hamilton 7 | 8 | // Permission is hereby granted, free of charge, to any person obtaining a copy 9 | // of this software and associated documentation files (the "Software"), to deal 10 | // in the Software without restriction, including without limitation the rights 11 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the Software is 13 | // furnished to do so, subject to the following conditions: 14 | 15 | // The above copyright notice and this permission notice shall be included in all 16 | // copies or substantial portions of the Software. 17 | 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | // SOFTWARE. 25 | #endregion License 26 | 27 | using System; 28 | 29 | namespace Dapper.Extra.Annotations 30 | { 31 | /// 32 | /// A named column in a database table. 33 | /// 34 | [AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = true)] 35 | public class ColumnAttribute : Attribute 36 | { 37 | /// 38 | /// Initializes a new instance of the class. 39 | /// 40 | /// The name of the column. 41 | public ColumnAttribute(string name) 42 | { 43 | Name = name; 44 | } 45 | 46 | /// 47 | /// The name of the column. 48 | /// 49 | public string Name { get; } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /DapperExtraCRUD/Extra/Annotations/IDefaultAttribute.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Released under MIT License 3 | // License: https://opensource.org/licenses/MIT 4 | // Home page: https://github.com/ffhighwind/DapperExtraCRUD 5 | 6 | // Copyright(c) 2018 Wesley Hamilton 7 | 8 | // Permission is hereby granted, free of charge, to any person obtaining a copy 9 | // of this software and associated documentation files (the "Software"), to deal 10 | // in the Software without restriction, including without limitation the rights 11 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the Software is 13 | // furnished to do so, subject to the following conditions: 14 | 15 | // The above copyright notice and this permission notice shall be included in all 16 | // copies or substantial portions of the Software. 17 | 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | // SOFTWARE. 25 | #endregion License 26 | 27 | namespace Dapper.Extra.Annotations 28 | { 29 | /// 30 | /// Base class for , , and . 31 | /// 32 | public interface IDefaultAttribute 33 | { 34 | /// 35 | /// Determines if the column should be automatically synchronized with the database. 36 | /// 37 | bool AutoSync { get; } 38 | 39 | /// 40 | /// Determines if the property has a value. 41 | /// 42 | bool HasValue { get; } 43 | 44 | /// 45 | /// The value to be substituted for the property's value. 46 | /// 47 | string Value { get; } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /DapperExtraCRUD/Extra/Annotations/IgnoreDeleteAttribute.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Released under MIT License 3 | // License: https://opensource.org/licenses/MIT 4 | // Home page: https://github.com/ffhighwind/DapperExtraCRUD 5 | 6 | // Copyright(c) 2018 Wesley Hamilton 7 | 8 | // Permission is hereby granted, free of charge, to any person obtaining a copy 9 | // of this software and associated documentation files (the "Software"), to deal 10 | // in the Software without restriction, including without limitation the rights 11 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the Software is 13 | // furnished to do so, subject to the following conditions: 14 | 15 | // The above copyright notice and this permission notice shall be included in all 16 | // copies or substantial portions of the Software. 17 | 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | // SOFTWARE. 25 | #endregion License 26 | 27 | using System; 28 | 29 | namespace Dapper.Extra.Annotations 30 | { 31 | /// 32 | /// Ignores the property for deletes. 33 | /// 34 | [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)] 35 | public class IgnoreDeleteAttribute : Attribute 36 | { 37 | /// 38 | /// Initializes a new instance of the class. 39 | /// 40 | public IgnoreDeleteAttribute() 41 | { 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /DapperExtraCRUD/Extra/Annotations/IgnoreInsertAttribute.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Released under MIT License 3 | // License: https://opensource.org/licenses/MIT 4 | // Home page: https://github.com/ffhighwind/DapperExtraCRUD 5 | 6 | // Copyright(c) 2018 Wesley Hamilton 7 | 8 | // Permission is hereby granted, free of charge, to any person obtaining a copy 9 | // of this software and associated documentation files (the "Software"), to deal 10 | // in the Software without restriction, including without limitation the rights 11 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the Software is 13 | // furnished to do so, subject to the following conditions: 14 | 15 | // The above copyright notice and this permission notice shall be included in all 16 | // copies or substantial portions of the Software. 17 | 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | // SOFTWARE. 25 | #endregion License 26 | 27 | using System; 28 | 29 | namespace Dapper.Extra.Annotations 30 | { 31 | /// 32 | /// Ignores the property for inserts. 33 | /// 34 | [AttributeUsage(AttributeTargets.Property | AttributeTargets.Class, AllowMultiple = false, Inherited = true)] 35 | public class IgnoreInsertAttribute : Attribute, IDefaultAttribute 36 | { 37 | /// 38 | /// Initializes a new instance of the class. 39 | /// 40 | public IgnoreInsertAttribute() 41 | { 42 | } 43 | 44 | /// 45 | /// Initializes a new instance of the class. 46 | /// 47 | /// A string that is substituted for the column's value on insert. 48 | /// If this is then the database's default value will be inserted instead. 49 | /// Determines if this column will be automatically selected after an insert. 50 | public IgnoreInsertAttribute(string value, bool autoSync = false) 51 | { 52 | AutoSync = autoSync; 53 | if (!string.IsNullOrWhiteSpace(value)) { 54 | Value = "(" + value.Trim() + ")"; 55 | } 56 | } 57 | 58 | /// 59 | /// Determines if this column will be automatically selected after an insert. 60 | /// 61 | public bool AutoSync { get; } 62 | 63 | /// 64 | /// Checks if the value is . 65 | /// 66 | public bool HasValue => Value != null; 67 | 68 | /// 69 | /// A string that is substituted for the column's value on insert. 70 | /// If this is then the database's default value will be inserted instead. 71 | /// 72 | public string Value { get; } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /DapperExtraCRUD/Extra/Annotations/IgnoreSelectAttribute.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Released under MIT License 3 | // License: https://opensource.org/licenses/MIT 4 | // Home page: https://github.com/ffhighwind/DapperExtraCRUD 5 | 6 | // Copyright(c) 2018 Wesley Hamilton 7 | 8 | // Permission is hereby granted, free of charge, to any person obtaining a copy 9 | // of this software and associated documentation files (the "Software"), to deal 10 | // in the Software without restriction, including without limitation the rights 11 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the Software is 13 | // furnished to do so, subject to the following conditions: 14 | 15 | // The above copyright notice and this permission notice shall be included in all 16 | // copies or substantial portions of the Software. 17 | 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | // SOFTWARE. 25 | #endregion License 26 | 27 | using System; 28 | 29 | namespace Dapper.Extra.Annotations 30 | { 31 | /// 32 | /// Ignores the property for selects. 33 | /// 34 | [AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = true)] 35 | public class IgnoreSelectAttribute : Attribute 36 | { 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /DapperExtraCRUD/Extra/Annotations/IgnoreUpdateAttribute.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Released under MIT License 3 | // License: https://opensource.org/licenses/MIT 4 | // Home page: https://github.com/ffhighwind/DapperExtraCRUD 5 | 6 | // Copyright(c) 2018 Wesley Hamilton 7 | 8 | // Permission is hereby granted, free of charge, to any person obtaining a copy 9 | // of this software and associated documentation files (the "Software"), to deal 10 | // in the Software without restriction, including without limitation the rights 11 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the Software is 13 | // furnished to do so, subject to the following conditions: 14 | 15 | // The above copyright notice and this permission notice shall be included in all 16 | // copies or substantial portions of the Software. 17 | 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | // SOFTWARE. 25 | #endregion License 26 | 27 | using System; 28 | 29 | namespace Dapper.Extra.Annotations 30 | { 31 | /// 32 | /// Ignores the property for updates. 33 | /// 34 | [AttributeUsage(AttributeTargets.Property | AttributeTargets.Class, AllowMultiple = false, Inherited = true)] 35 | public class IgnoreUpdateAttribute : Attribute, IDefaultAttribute 36 | { 37 | /// 38 | /// Initializes a new instance of the class. 39 | /// 40 | public IgnoreUpdateAttribute() 41 | { 42 | } 43 | 44 | /// 45 | /// Initializes a new instance of the class. 46 | /// 47 | /// A string that is substituted for the column's value on update. 48 | /// If this is then the column will not be updated. 49 | /// Determines if the property should be selected to match the database after an update. 50 | public IgnoreUpdateAttribute(string value, bool autoSync = false) 51 | { 52 | AutoSync = autoSync; 53 | if (!string.IsNullOrWhiteSpace(value)) { 54 | Value = "(" + value.Trim() + ")"; 55 | } 56 | } 57 | 58 | /// 59 | /// Determines if this column will be automatically selected after an update. 60 | /// 61 | public bool AutoSync { get; } 62 | 63 | /// 64 | /// Checks if the value is . 65 | /// 66 | public bool HasValue => Value != null; 67 | 68 | /// 69 | /// A string that is substituted for the column's value on update. 70 | /// If this is then the column will not be updated. 71 | /// 72 | public string Value { get; } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /DapperExtraCRUD/Extra/Annotations/KeyAttribute.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Released under MIT License 3 | // License: https://opensource.org/licenses/MIT 4 | // Home page: https://github.com/ffhighwind/DapperExtraCRUD 5 | 6 | // Copyright(c) 2018 Wesley Hamilton 7 | 8 | // Permission is hereby granted, free of charge, to any person obtaining a copy 9 | // of this software and associated documentation files (the "Software"), to deal 10 | // in the Software without restriction, including without limitation the rights 11 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the Software is 13 | // furnished to do so, subject to the following conditions: 14 | 15 | // The above copyright notice and this permission notice shall be included in all 16 | // copies or substantial portions of the Software. 17 | 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | // SOFTWARE. 25 | #endregion License 26 | 27 | using System; 28 | 29 | namespace Dapper.Extra.Annotations 30 | { 31 | /// 32 | /// A primary key column. 33 | /// 34 | [AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = false)] 35 | public class KeyAttribute : Attribute 36 | { 37 | /// 38 | /// Initializes a new instance of the class. 39 | /// 40 | /// Determines if the primary key is an identity (auto-incrementing). 41 | /// This is ignored if it is not an integral property type (, 42 | /// , , etc). 43 | public KeyAttribute(bool autoIncrement = true) 44 | { 45 | AutoIncrement = autoIncrement; 46 | } 47 | 48 | /// 49 | /// Determines if the primary key is an identity (auto-incrementing). 50 | /// This is ignored if it is not an integral property type (, 51 | /// , , etc). 52 | /// 53 | public bool AutoIncrement { get; private set; } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /DapperExtraCRUD/Extra/Annotations/MatchDeleteAttribute.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Released under MIT License 3 | // License: https://opensource.org/licenses/MIT 4 | // Home page: https://github.com/ffhighwind/DapperExtraCRUD 5 | 6 | // Copyright(c) 2018 Wesley Hamilton 7 | 8 | // Permission is hereby granted, free of charge, to any person obtaining a copy 9 | // of this software and associated documentation files (the "Software"), to deal 10 | // in the Software without restriction, including without limitation the rights 11 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the Software is 13 | // furnished to do so, subject to the following conditions: 14 | 15 | // The above copyright notice and this permission notice shall be included in all 16 | // copies or substantial portions of the Software. 17 | 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | // SOFTWARE. 25 | #endregion 26 | 27 | using System; 28 | 29 | namespace Dapper.Extra.Annotations 30 | { 31 | /// 32 | /// Turns a property into a pseudo key for deletions. 33 | /// 34 | [AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = true)] 35 | public class MatchDeleteAttribute : Attribute 36 | { 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /DapperExtraCRUD/Extra/Annotations/MatchUpdateAttribute.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Released under MIT License 3 | // License: https://opensource.org/licenses/MIT 4 | // Home page: https://github.com/ffhighwind/DapperExtraCRUD 5 | 6 | // Copyright(c) 2018 Wesley Hamilton 7 | 8 | // Permission is hereby granted, free of charge, to any person obtaining a copy 9 | // of this software and associated documentation files (the "Software"), to deal 10 | // in the Software without restriction, including without limitation the rights 11 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the Software is 13 | // furnished to do so, subject to the following conditions: 14 | 15 | // The above copyright notice and this permission notice shall be included in all 16 | // copies or substantial portions of the Software. 17 | 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | // SOFTWARE. 25 | #endregion License 26 | 27 | using System; 28 | 29 | namespace Dapper.Extra.Annotations 30 | { 31 | /// 32 | /// Turns the property into a pseudo key for updates. 33 | /// 34 | [AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = true)] 35 | public class MatchUpdateAttribute : Attribute, IDefaultAttribute 36 | { 37 | /// 38 | /// Initializes a new instance of the class. 39 | /// 40 | public MatchUpdateAttribute() 41 | { 42 | } 43 | 44 | /// 45 | /// Initializes a new instance of the class. 46 | /// 47 | /// A string that is substituted for the column's value on insert. 48 | /// If this is then the column will not be updated. 49 | /// Determines if the property should be selected to match the database after an update. 50 | public MatchUpdateAttribute(string value, bool autoSync = false) 51 | { 52 | AutoSync = autoSync; 53 | if (!string.IsNullOrWhiteSpace(value)) { 54 | Value = "(" + value.Trim() + ")"; 55 | } 56 | } 57 | 58 | /// 59 | /// Determines if this column will be automatically selected after an update. 60 | /// 61 | public bool AutoSync { get; } 62 | 63 | /// 64 | /// Checks if the value is . 65 | /// 66 | public bool HasValue => Value != null; 67 | 68 | /// 69 | /// A string that is substituted for the column's value on insert. 70 | /// If this is then the column will not be updated. 71 | /// 72 | public string Value { get; } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /DapperExtraCRUD/Extra/Annotations/NotMappedAttribute.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Released under MIT License 3 | // License: https://opensource.org/licenses/MIT 4 | // Home page: https://github.com/ffhighwind/DapperExtraCRUD 5 | 6 | // Copyright(c) 2018 Wesley Hamilton 7 | 8 | // Permission is hereby granted, free of charge, to any person obtaining a copy 9 | // of this software and associated documentation files (the "Software"), to deal 10 | // in the Software without restriction, including without limitation the rights 11 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the Software is 13 | // furnished to do so, subject to the following conditions: 14 | 15 | // The above copyright notice and this permission notice shall be included in all 16 | // copies or substantial portions of the Software. 17 | 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | // SOFTWARE. 25 | #endregion 26 | 27 | using System; 28 | 29 | namespace Dapper.Extra.Annotations 30 | { 31 | /// 32 | /// Prevents the property from being mapped. 33 | /// 34 | [AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = false)] 35 | public class NotMappedAttribute : Attribute 36 | { 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /DapperExtraCRUD/Extra/Annotations/TableAttribute.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Released under MIT License 3 | // License: https://opensource.org/licenses/MIT 4 | // Home page: https://github.com/ffhighwind/DapperExtraCRUD 5 | 6 | // Copyright(c) 2018 Wesley Hamilton 7 | 8 | // Permission is hereby granted, free of charge, to any person obtaining a copy 9 | // of this software and associated documentation files (the "Software"), to deal 10 | // in the Software without restriction, including without limitation the rights 11 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the Software is 13 | // furnished to do so, subject to the following conditions: 14 | 15 | // The above copyright notice and this permission notice shall be included in all 16 | // copies or substantial portions of the Software. 17 | 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | // SOFTWARE. 25 | #endregion 26 | 27 | using System; 28 | using System.Threading; 29 | 30 | namespace Dapper.Extra.Annotations 31 | { 32 | /// 33 | /// The name of the database table. If this is not supplied then the table name is assumed to be the same as the name. 34 | /// 35 | /// 36 | [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)] 37 | public class TableAttribute : Attribute 38 | { 39 | /// 40 | /// Initializes a new instance of the class. 41 | /// 42 | /// The name of the table. 43 | /// The schema of the table. This is only for user reference and is completely ignored. 44 | /// Determines if only top-level properties are used. Subclass properties are ignored if this is true. 45 | /// Determines if attributes are inherited. 46 | /// The dialect to use when generating SQL commands. If this is null then it will store the default dialect 47 | /// from the first time it is accessed. 48 | public TableAttribute(string name = null, string schema = null, bool declaredOnly = false, bool inheritAttrs = true, SqlDialect dialect = 0) 49 | { 50 | Name = name?.Trim(); 51 | Schema = string.IsNullOrWhiteSpace(schema) ? null : schema.Trim(); 52 | InheritAttributes = inheritAttrs; 53 | DeclaredOnly = declaredOnly; 54 | Dialect = dialect; 55 | } 56 | 57 | /// 58 | /// Determines if only top-level properties are used. Subclass properties are ignored if this is true. 59 | /// 60 | public bool DeclaredOnly { get; protected set; } 61 | 62 | /// 63 | /// Determines if property attributes are inherited. 64 | /// 65 | public bool InheritAttributes { get; protected set; } 66 | 67 | /// 68 | /// The name of the table. 69 | /// 70 | public string Name { get; protected set; } 71 | 72 | /// 73 | /// The schema of the table. 74 | /// 75 | public string Schema { get; protected set; } 76 | 77 | protected Lazy LazyDialect; 78 | /// 79 | /// The dialect to use when generating SQL commands. 80 | /// 81 | public SqlDialect Dialect { 82 | get => LazyDialect.Value; 83 | set => LazyDialect = value <= 0 ? new Lazy(() => ExtraCrud.Dialect, LazyThreadSafetyMode.None) 84 | : new Lazy(() => value, LazyThreadSafetyMode.None); 85 | } 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /DapperExtraCRUD/Extra/ISqlBuilder.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Released under MIT License 3 | // License: https://opensource.org/licenses/MIT 4 | // Home page: https://github.com/ffhighwind/DapperExtraCRUD 5 | 6 | // Copyright(c) 2018 Wesley Hamilton 7 | 8 | // Permission is hereby granted, free of charge, to any person obtaining a copy 9 | // of this software and associated documentation files (the "Software"), to deal 10 | // in the Software without restriction, including without limitation the rights 11 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the Software is 13 | // furnished to do so, subject to the following conditions: 14 | 15 | // The above copyright notice and this permission notice shall be included in all 16 | // copies or substantial portions of the Software. 17 | 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | // SOFTWARE. 25 | #endregion 26 | 27 | using System; 28 | using System.Collections.Generic; 29 | 30 | namespace Dapper.Extra 31 | { 32 | /// 33 | /// Stores metadata and generates SQL commands. 34 | /// 35 | public interface ISqlBuilder 36 | { 37 | /// 38 | /// The valid columns for the given type. 39 | /// 40 | IReadOnlyList Columns { get; } 41 | 42 | /// 43 | /// Stores metadata for for the given type. 44 | /// 45 | SqlTypeInfo Info { get; } 46 | 47 | /// 48 | /// The dialect used to generate SQL commands. 49 | /// 50 | SqlDialect Dialect { get; } 51 | 52 | /// 53 | /// The quoted table name or the class name. 54 | /// 55 | string FullyQualifiedTableName { get; } 56 | 57 | /// 58 | /// Gets the subset of columns that match the property names of . 59 | /// 60 | /// The type whose properties to match. 61 | /// A list of columns from . 62 | /// The subset of columns that match the property names of . 63 | IEnumerable GetSharedColumns(Type type, IEnumerable columns); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /DapperExtraCRUD/Extra/ISqlQueries.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Released under MIT License 3 | // License: https://opensource.org/licenses/MIT 4 | // Home page: https://github.com/ffhighwind/DapperExtraCRUD 5 | 6 | // Copyright(c) 2018 Wesley Hamilton 7 | 8 | // Permission is hereby granted, free of charge, to any person obtaining a copy 9 | // of this software and associated documentation files (the "Software"), to deal 10 | // in the Software without restriction, including without limitation the rights 11 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the Software is 13 | // furnished to do so, subject to the following conditions: 14 | 15 | // The above copyright notice and this permission notice shall be included in all 16 | // copies or substantial portions of the Software. 17 | 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | // SOFTWARE. 25 | #endregion 26 | 27 | using System; 28 | using System.Linq.Expressions; 29 | using Dapper.Extra.Utilities; 30 | 31 | namespace Dapper.Extra 32 | { 33 | /// 34 | /// The SQL commands for a given type. 35 | /// 36 | /// The table type. 37 | public interface ISqlQueries where T : class 38 | { 39 | /// 40 | /// Compiles an expression using and stores the result. 41 | /// This may use a cache to prevent compilation. 42 | /// 43 | /// The predicate to use for the query. 44 | /// The compiled result from passing the expression to . 45 | WhereConditionData Compile(Expression> predicate); 46 | 47 | /// 48 | /// Bulk delete command for any key type. 49 | /// 50 | DbListInt BulkDelete { get; } 51 | 52 | /// 53 | /// Bulk delete command for single-value keys. 54 | /// 55 | DbKeysInt BulkDeleteKeys { get; } 56 | 57 | /// 58 | /// Bulk select command for any key type. 59 | /// 60 | DbListList BulkGet { get; } 61 | 62 | /// 63 | /// Bulk select command for single-value keys. 64 | /// 65 | DbKeysList BulkGetKeys { get; } 66 | 67 | /// 68 | /// Bulk insert command for any key type. 69 | /// 70 | DbListVoid BulkInsert { get; } 71 | 72 | /// 73 | /// Bulk insert-if-not-exists command. 74 | /// 75 | DbListInt BulkInsertIfNotExists { get; } 76 | 77 | /// 78 | /// Bulk update command for any key type. 79 | /// 80 | DbListInt BulkUpdate { get; } 81 | 82 | /// 83 | /// Bulk upsert (insert or update) command. 84 | /// 85 | DbListInt BulkUpsert { get; } 86 | 87 | /// 88 | /// Delete command for any key type. 89 | /// 90 | DbTBool Delete { get; } 91 | 92 | /// 93 | /// Delete command for a single key. 94 | /// 95 | DbKeyBool DeleteKey { get; } 96 | 97 | /// 98 | /// Delete command for a given condition. 99 | /// 100 | DbWhereInt DeleteList { get; } 101 | 102 | /// 103 | /// Select command for any key type. 104 | /// 105 | DbTT Get { get; } 106 | 107 | /// 108 | /// Select distinct command which is filtered to a subset of columns. 109 | /// 110 | DbTypeWhereList GetDistinct { get; } 111 | 112 | /// 113 | /// Select distinct command which is filtered to a subset of columns and limited to a certain number of rows. 114 | /// 115 | DbTypeLimitList GetDistinctLimit { get; } 116 | 117 | /// 118 | /// Select command which is filtered to a subset of columns. 119 | /// 120 | DbTypeWhereList GetFilter { get; } 121 | 122 | /// 123 | /// Select command which is filtered to a subset of columns. 124 | /// 125 | DbTypeLimitList GetFilterLimit { get; } 126 | 127 | /// 128 | /// Select command for a single key. 129 | /// 130 | DbKeyObj GetKey { get; } 131 | 132 | /// 133 | /// Select command for a given condition. 134 | /// 135 | DbWhereList GetKeys { get; } 136 | 137 | /// 138 | /// Select command for a given condition which returns single-value keys. 139 | /// 140 | DbWhereKeys GetKeysKeys { get; } 141 | 142 | /// 143 | /// Select command which is limited to a certain number of rows. 144 | /// 145 | DbLimitList GetLimit { get; } 146 | 147 | /// 148 | /// Select command for a given condition. 149 | /// 150 | DbWhereList GetList { get; } 151 | 152 | /// 153 | /// Insert command. 154 | /// 155 | DbTVoid Insert { get; } 156 | 157 | /// 158 | /// Auto-sync command for inserts. 159 | /// 160 | DbTVoid InsertAutoSync { get; } 161 | 162 | /// 163 | /// Insert-if-not-exists command. 164 | /// 165 | DbTBool InsertIfNotExists { get; } 166 | 167 | /// 168 | /// Count command for a given condition. 169 | /// 170 | DbWhereInt RecordCount { get; } 171 | 172 | /// 173 | /// Truncate command. 174 | /// 175 | DbVoid Truncate { get; } 176 | 177 | /// 178 | /// Update command. 179 | /// 180 | DbTBool Update { get; } 181 | 182 | /// 183 | /// Auto-sync command for updates. 184 | /// 185 | DbTVoid UpdateAutoSync { get; } 186 | 187 | /// 188 | /// Update command for a subset of columns. 189 | /// 190 | DbObjBool UpdateObj { get; } 191 | 192 | /// 193 | /// Upsert (insert or update) command. 194 | /// 195 | DbTBool Upsert { get; } 196 | } 197 | } 198 | -------------------------------------------------------------------------------- /DapperExtraCRUD/Extra/Internal/Constants.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Released under MIT License 3 | // License: https://opensource.org/licenses/MIT 4 | // Home page: https://github.com/ffhighwind/DapperExtraCRUD 5 | 6 | // Copyright(c) 2018 Wesley Hamilton 7 | 8 | // Permission is hereby granted, free of charge, to any person obtaining a copy 9 | // of this software and associated documentation files (the "Software"), to deal 10 | // in the Software without restriction, including without limitation the rights 11 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the Software is 13 | // furnished to do so, subject to the following conditions: 14 | 15 | // The above copyright notice and this permission notice shall be included in all 16 | // copies or substantial portions of the Software. 17 | 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | // SOFTWARE. 25 | #endregion 26 | 27 | using System; 28 | 29 | namespace Dapper.Extra.Internal 30 | { 31 | /// 32 | /// Framework specific constants. 33 | /// 34 | internal static class Constants 35 | { 36 | #if NET45 37 | public static readonly SqlColumn[] SqlColumnsEmpty = new SqlColumn[0]; 38 | #else 39 | public static SqlColumn[] SqlColumnsEmpty => Array.Empty(); 40 | #endif 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /DapperExtraCRUD/Extra/Internal/SqlQueries.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Released under MIT License 3 | // License: https://opensource.org/licenses/MIT 4 | // Home page: https://github.com/ffhighwind/DapperExtraCRUD 5 | 6 | // Copyright(c) 2018 Wesley Hamilton 7 | 8 | // Permission is hereby granted, free of charge, to any person obtaining a copy 9 | // of this software and associated documentation files (the "Software"), to deal 10 | // in the Software without restriction, including without limitation the rights 11 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the Software is 13 | // furnished to do so, subject to the following conditions: 14 | 15 | // The above copyright notice and this permission notice shall be included in all 16 | // copies or substantial portions of the Software. 17 | 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | // SOFTWARE. 25 | #endregion 26 | 27 | using System; 28 | using System.Linq.Expressions; 29 | 30 | namespace Dapper.Extra 31 | { 32 | internal class SqlQueries : ISqlQueries where T : class 33 | { 34 | public volatile int index = 0; 35 | private const int CACHE_SIZE = 3; 36 | public WhereConditionData[] WhereConditionCache { get; set; } = new WhereConditionData[CACHE_SIZE]; 37 | public WhereConditionData Compile(Expression> predicate) 38 | { 39 | WhereConditionData data; 40 | int prevIndex = index; 41 | int i = prevIndex; 42 | do { 43 | data = WhereConditionCache[i]; 44 | if (data == null) 45 | break; 46 | if (data.Predicate == predicate) 47 | return data; 48 | i = (i + 1) % CACHE_SIZE; 49 | } while (i != prevIndex); 50 | data = new WhereConditionData(predicate); 51 | prevIndex = (index - 1 + CACHE_SIZE) % CACHE_SIZE; 52 | index = prevIndex; 53 | WhereConditionCache[prevIndex] = data; 54 | return data; 55 | } 56 | 57 | public DbListInt BulkDelete => LazyBulkDelete.Value; 58 | 59 | public DbKeysInt BulkDeleteKeys => LazyBulkDeleteKeys.Value; 60 | 61 | public DbListList BulkGet => LazyBulkGet.Value; 62 | 63 | public DbKeysList BulkGetKeys => LazyBulkGetKeys.Value; 64 | 65 | public DbListVoid BulkInsert => LazyBulkInsert.Value; 66 | 67 | public DbListInt BulkInsertIfNotExists => LazyBulkInsertIfNotExists.Value; 68 | 69 | public DbListInt BulkUpdate => LazyBulkUpdate.Value; 70 | 71 | public DbListInt BulkUpsert => LazyBulkUpsert.Value; 72 | 73 | public DbTBool Delete { get; internal set; } 74 | 75 | public DbKeyBool DeleteKey { get; internal set; } 76 | 77 | public DbWhereInt DeleteList => LazyDeleteList.Value; 78 | 79 | public DbTT Get { get; internal set; } 80 | 81 | public DbTypeWhereList GetDistinct => LazyGetDistinct.Value; 82 | 83 | public DbTypeLimitList GetDistinctLimit => LazyGetDistinctLimit.Value; 84 | 85 | public DbTypeWhereList GetFilter => LazyGetFilter.Value; 86 | 87 | public DbTypeLimitList GetFilterLimit => LazyGetFilterLimit.Value; 88 | 89 | public DbKeyObj GetKey { get; internal set; } 90 | 91 | public DbWhereList GetKeys => LazyGetKeys.Value; 92 | 93 | public DbWhereKeys GetKeysKeys => LazyGetKeysKeys.Value; 94 | 95 | public DbLimitList GetLimit => LazyGetLimit.Value; 96 | 97 | public DbWhereList GetList { get; internal set; } 98 | 99 | public DbTVoid Insert { get; internal set; } 100 | 101 | public DbTVoid InsertAutoSync { get; internal set; } 102 | 103 | public DbTBool InsertIfNotExists => LazyInsertIfNotExists.Value; 104 | 105 | public DbWhereInt RecordCount => LazyRecordCount.Value; 106 | 107 | public DbVoid Truncate => LazyTruncate.Value; 108 | 109 | public DbTBool Update { get; internal set; } 110 | 111 | public DbTVoid UpdateAutoSync { get; internal set; } 112 | 113 | public DbObjBool UpdateObj => LazyUpdateObj.Value; 114 | 115 | public DbTBool Upsert => LazyUpsert.Value; 116 | 117 | internal Lazy> LazyBulkDelete { get; set; } 118 | 119 | internal Lazy> LazyBulkDeleteKeys { get; set; } 120 | 121 | internal Lazy> LazyBulkGet { get; set; } 122 | 123 | internal Lazy> LazyBulkGetKeys { get; set; } 124 | 125 | internal Lazy> LazyBulkInsert { get; set; } 126 | 127 | internal Lazy> LazyBulkInsertIfNotExists { get; set; } 128 | 129 | internal Lazy> LazyBulkUpdate { get; set; } 130 | 131 | internal Lazy> LazyBulkUpsert { get; set; } 132 | 133 | internal Lazy> LazyDeleteList { get; set; } 134 | 135 | internal Lazy> LazyGetDistinct { get; set; } 136 | 137 | internal Lazy> LazyGetDistinctLimit { get; set; } 138 | 139 | internal Lazy> LazyGetFilter { get; set; } 140 | 141 | internal Lazy> LazyGetFilterLimit { get; set; } 142 | 143 | internal Lazy> LazyGetKeys { get; set; } 144 | 145 | internal Lazy LazyGetKeysKeys { get; set; } 146 | 147 | internal Lazy> LazyGetLimit { get; set; } 148 | 149 | internal Lazy> LazyInsertIfNotExists { get; set; } 150 | 151 | internal Lazy> LazyRecordCount { get; set; } 152 | 153 | internal Lazy LazyTruncate { get; set; } 154 | 155 | internal Lazy> LazyUpdateObj { get; set; } 156 | 157 | internal Lazy> LazyUpsert { get; set; } 158 | } 159 | } 160 | -------------------------------------------------------------------------------- /DapperExtraCRUD/Extra/SqlAdapter.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Released under MIT License 3 | // License: https://opensource.org/licenses/MIT 4 | // Home page: https://github.com/ffhighwind/DapperExtraCRUD 5 | 6 | // Copyright(c) 2018 Wesley Hamilton 7 | 8 | // Permission is hereby granted, free of charge, to any person obtaining a copy 9 | // of this software and associated documentation files (the "Software"), to deal 10 | // in the Software without restriction, including without limitation the rights 11 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the Software is 13 | // furnished to do so, subject to the following conditions: 14 | 15 | // The above copyright notice and this permission notice shall be included in all 16 | // copies or substantial portions of the Software. 17 | 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | // SOFTWARE. 25 | #endregion 26 | 27 | using Dapper.Extra.Internal.Adapters; 28 | 29 | namespace Dapper.Extra 30 | { 31 | /// 32 | /// Generates specialized commands using a given dialect. 33 | /// 34 | public abstract class SqlAdapter 35 | { 36 | /// 37 | /// An that generates SQL commands for MySQL. 38 | /// 39 | public static readonly ISqlAdapter MySQL = new MySqlAdapter(); 40 | 41 | /// 42 | /// An that generates SQL commands for PostgreSQL. 43 | /// 44 | public static readonly ISqlAdapter PostgreSQL = new PostgreSqlAdapter(); 45 | 46 | /// 47 | /// An that generates SQL commands for SQLite. 48 | /// 49 | public static readonly ISqlAdapter SQLite = new SqlLiteAdapter(); 50 | 51 | /// 52 | /// An that generates SQL commands for Microsoft SQL Server. 53 | /// 54 | public static readonly ISqlAdapter SQLServer = new SqlServerAdapter(); 55 | 56 | /// 57 | /// Gets the that matches a given . 58 | /// 59 | /// The dialect of the . 60 | /// The that matches a given . 61 | public static ISqlAdapter GetAdapter(SqlDialect dialect) 62 | { 63 | switch (dialect) { 64 | case SqlDialect.MySQL: 65 | return MySQL; 66 | case SqlDialect.PostgreSQL: 67 | return PostgreSQL; 68 | case SqlDialect.SQLite: 69 | return SQLite; 70 | case SqlDialect.SQLServer: 71 | default: 72 | return SQLServer; 73 | } 74 | } 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /DapperExtraCRUD/Extra/SqlColumnAttributes.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Released under MIT License 3 | // License: https://opensource.org/licenses/MIT 4 | // Home page: https://github.com/ffhighwind/DapperExtraCRUD 5 | 6 | // Copyright(c) 2018 Wesley Hamilton 7 | 8 | // Permission is hereby granted, free of charge, to any person obtaining a copy 9 | // of this software and associated documentation files (the "Software"), to deal 10 | // in the Software without restriction, including without limitation the rights 11 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the Software is 13 | // furnished to do so, subject to the following conditions: 14 | 15 | // The above copyright notice and this permission notice shall be included in all 16 | // copies or substantial portions of the Software. 17 | 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | // SOFTWARE. 25 | #endregion 26 | 27 | namespace Dapper.Extra 28 | { 29 | /// 30 | /// The accepted attributes for the column. 31 | /// 32 | public enum SqlColumnAttributes 33 | { 34 | /// 35 | /// No column attributes. 36 | /// 37 | None = 0, 38 | /// 39 | /// The column is part of the primary key. 40 | /// 41 | Key = 1, 42 | /// 43 | /// The column is an auto-increment key. 44 | /// 45 | AutoKey = (1 << 1) | Key, 46 | /// 47 | /// Ignores the column for selects. 48 | /// 49 | IgnoreSelect = 1 << 2, 50 | /// 51 | /// Ignores the column for inserts. 52 | /// 53 | IgnoreInsert = 1 << 3, 54 | /// 55 | /// Ignores the column for updates. 56 | /// 57 | IgnoreUpdate = 1 << 4, 58 | /// 59 | /// Ignores the column for inserts. 60 | /// 61 | IgnoreDelete = 1 << 5, 62 | /// 63 | /// Determines if the column must match the database on deletes. 64 | /// 65 | MatchDelete = 1 << 6, 66 | /// 67 | /// Determines if the column must matched the database on updates. 68 | /// 69 | MatchUpdate = 1 << 7, 70 | /// 71 | /// Prevents the column from being included in commands. 72 | /// 73 | NotMapped = IgnoreSelect | IgnoreInsert | IgnoreUpdate | IgnoreDelete, 74 | /// 75 | /// Determines if the column should be synchronized after inserts. 76 | /// 77 | InsertAutoSync = 1 << 8, 78 | /// 79 | /// Determines if the column should be synchronized after updates. 80 | /// 81 | UpdateAutoSync = 1 << 9, 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /DapperExtraCRUD/Extra/SqlDialect.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Released under MIT License 3 | // License: https://opensource.org/licenses/MIT 4 | // Home page: https://github.com/ffhighwind/DapperExtraCRUD 5 | 6 | // Copyright(c) 2018 Wesley Hamilton 7 | 8 | // Permission is hereby granted, free of charge, to any person obtaining a copy 9 | // of this software and associated documentation files (the "Software"), to deal 10 | // in the Software without restriction, including without limitation the rights 11 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the Software is 13 | // furnished to do so, subject to the following conditions: 14 | 15 | // The above copyright notice and this permission notice shall be included in all 16 | // copies or substantial portions of the Software. 17 | 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | // SOFTWARE. 25 | #endregion 26 | 27 | namespace Dapper.Extra 28 | { 29 | /// 30 | /// Represents and RDBMS dialect used for generating queries. 31 | /// 32 | public enum SqlDialect 33 | { 34 | /// 35 | /// Microsoft SQL Server 36 | /// 37 | SQLServer = 1, 38 | /// 39 | /// PostgreSQL 40 | /// 41 | PostgreSQL = 2, 42 | /// 43 | /// MySQL 44 | /// 45 | MySQL = 3, 46 | /// 47 | /// SQLite 48 | /// 49 | SQLite = 4, 50 | //Oracle, 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /DapperExtraCRUD/Extra/SqlTableAttributes.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Released under MIT License 3 | // License: https://opensource.org/licenses/MIT 4 | // Home page: https://github.com/ffhighwind/DapperExtraCRUD 5 | 6 | // Copyright(c) 2018 Wesley Hamilton 7 | 8 | // Permission is hereby granted, free of charge, to any person obtaining a copy 9 | // of this software and associated documentation files (the "Software"), to deal 10 | // in the Software without restriction, including without limitation the rights 11 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the Software is 13 | // furnished to do so, subject to the following conditions: 14 | 15 | // The above copyright notice and this permission notice shall be included in all 16 | // copies or substantial portions of the Software. 17 | 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | // SOFTWARE. 25 | #endregion 26 | 27 | namespace Dapper.Extra 28 | { 29 | /// 30 | /// The attributes for the class. 31 | /// 32 | public enum SqlTableAttributes 33 | { 34 | /// 35 | /// No table attributes. 36 | /// 37 | None = 0, 38 | /// 39 | /// Prevent inherited properties. 40 | /// 41 | DeclaredOnly = 1, 42 | /// 43 | /// Include inherited attributes. 44 | /// 45 | InheritAttributes = 1 << 1, 46 | 47 | //IgnoreSelect = 1 << 2, 48 | 49 | /// 50 | /// Prevents insert commands. 51 | /// 52 | IgnoreInsert = 1 << 3, 53 | /// 54 | /// Prevents update commands. 55 | /// 56 | IgnoreUpdate = 1 << 4, 57 | /// 58 | /// Prevents delete commands. 59 | /// 60 | IgnoreDelete = 1 << 5, 61 | /// 62 | /// Determines if objects should be synchronized after inserts. 63 | /// 64 | InsertAutoSync = 1 << 8, 65 | /// 66 | /// Determines if objects should be synchronized after updates. 67 | /// 68 | UpdateAutoSync = 1 << 9, 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /DapperExtraCRUD/Extra/Utilities/ConnectedEnumerable.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Released under MIT License 3 | // License: https://opensource.org/licenses/MIT 4 | // Home page: https://github.com/ffhighwind/DapperExtraCRUD 5 | 6 | // Copyright(c) 2018 Wesley Hamilton 7 | 8 | // Permission is hereby granted, free of charge, to any person obtaining a copy 9 | // of this software and associated documentation files (the "Software"), to deal 10 | // in the Software without restriction, including without limitation the rights 11 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the Software is 13 | // furnished to do so, subject to the following conditions: 14 | 15 | // The above copyright notice and this permission notice shall be included in all 16 | // copies or substantial portions of the Software. 17 | 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | // SOFTWARE. 25 | #endregion 26 | 27 | using System.Collections; 28 | using System.Collections.Generic; 29 | using System.Data; 30 | 31 | namespace Dapper.Extra.Utilities 32 | { 33 | /// 34 | /// Allows an to stay open until the enumeration is completely traversed or it is disposed. 35 | /// This allows unbuffered queries to be returned. 36 | /// 37 | /// The type returned by the query. 38 | public class ConnectedEnumerable : IEnumerable 39 | { 40 | /// 41 | /// Initializes a new instance of the class. 42 | /// 43 | /// The list 44 | /// The connection 45 | public ConnectedEnumerable(IEnumerable list, IDbConnection connection) 46 | { 47 | List = list; 48 | Connection = connection; 49 | } 50 | 51 | /// 52 | /// The connection that should be closed once 53 | /// has been traversed completely. 54 | /// 55 | public IDbConnection Connection { get; private set; } 56 | 57 | /// 58 | /// The unbuffered result from the query. 59 | /// 60 | public IEnumerable List { get; private set; } 61 | 62 | /// 63 | /// The enumerator for . 64 | /// 65 | public IEnumerator GetEnumerator() 66 | { 67 | return new Enumerator(Connection, List.GetEnumerator()); 68 | } 69 | 70 | IEnumerator IEnumerable.GetEnumerator() 71 | { 72 | return new Enumerator(Connection, List.GetEnumerator()); 73 | } 74 | 75 | internal class Enumerator : IEnumerator 76 | { 77 | private readonly IEnumerator enumerator; 78 | 79 | private IDbConnection conn; 80 | 81 | private bool disposedValue = false;// To detect redundant calls 82 | 83 | /// 84 | /// Initializes a new instance of the class. 85 | /// 86 | /// The conn 87 | /// The enumerator 88 | public Enumerator(IDbConnection conn, IEnumerator enumerator) 89 | { 90 | this.conn = conn; 91 | this.enumerator = enumerator; 92 | } 93 | 94 | public T Current => enumerator.Current; 95 | 96 | object IEnumerator.Current => enumerator.Current; 97 | 98 | 99 | // TODO: override a finalizer only if Dispose(bool disposing) above has code to free unmanaged resources. 100 | // ~Enumerator() { 101 | // // Do not change this code. Put cleanup code in Dispose(bool disposing) above. 102 | // Dispose(false); 103 | // } 104 | 105 | // This code added to correctly implement the disposable pattern. 106 | public void Dispose() 107 | { 108 | // Do not change this code. Put cleanup code in Dispose(bool disposing) above. 109 | Dispose(true); 110 | } 111 | 112 | public bool MoveNext() 113 | { 114 | if (!enumerator.MoveNext()) { 115 | conn.Close(); 116 | return false; 117 | } 118 | return true; 119 | } 120 | 121 | public void Reset() 122 | { 123 | enumerator.Reset(); 124 | } 125 | 126 | protected virtual void Dispose(bool disposing) 127 | { 128 | if (!disposedValue) { 129 | if (disposing) { 130 | // TODO: dispose managed state (managed objects). 131 | } 132 | conn.Dispose(); 133 | conn = null; 134 | disposedValue = true; 135 | } 136 | } 137 | } 138 | } 139 | } 140 | -------------------------------------------------------------------------------- /DapperExtraCRUD/Extra/Utilities/IDataAccessObject.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Released under MIT License 3 | // License: https://opensource.org/licenses/MIT 4 | // Home page: https://github.com/ffhighwind/DapperExtraCRUD 5 | 6 | // Copyright(c) 2018 Wesley Hamilton 7 | 8 | // Permission is hereby granted, free of charge, to any person obtaining a copy 9 | // of this software and associated documentation files (the "Software"), to deal 10 | // in the Software without restriction, including without limitation the rights 11 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the Software is 13 | // furnished to do so, subject to the following conditions: 14 | 15 | // The above copyright notice and this permission notice shall be included in all 16 | // copies or substantial portions of the Software. 17 | 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | // SOFTWARE. 25 | #endregion 26 | 27 | using System.Data; 28 | 29 | namespace Dapper.Extra.Utilities 30 | { 31 | /// 32 | /// Interface for an object that interacts with a database. 33 | /// 34 | public interface IDataAccessObject 35 | { 36 | /// 37 | /// The connection used for queries. This will be temporarily opened it if is closed. 38 | /// This connection is not thread-safe because it is reused for all queries. 39 | /// 40 | IDbConnection Connection { get; set; } 41 | 42 | /// 43 | /// The transaction used for queries. 44 | /// 45 | IDbTransaction Transaction { get; set; } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /DapperExtraCRUD/Extra/WhereConditionData.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq.Expressions; 4 | using Dapper.Extra.Utilities; 5 | 6 | namespace Dapper.Extra 7 | { 8 | /// 9 | /// Stores the result of an expression using . 10 | /// 11 | /// The table type. 12 | public class WhereConditionData where T : class 13 | { 14 | /// 15 | /// Compiles an expression using and stores the result. 16 | /// 17 | /// The predicate to use for the query. 18 | public WhereConditionData(Expression> predicate) 19 | { 20 | WhereCondition = "WHERE " + WhereConditionGenerator.Create(predicate, out IDictionary param); 21 | Param = param; 22 | Predicate = predicate; 23 | } 24 | 25 | /// 26 | /// The predicate expression that was created. 27 | /// 28 | public Expression> Predicate { get; protected set; } 29 | 30 | /// 31 | /// The WHERE expression in SQL that the predicate represents. 32 | /// 33 | public string WhereCondition { get; protected set; } 34 | 35 | /// 36 | /// The Dapper parameters for the WHERE condition. 37 | /// 38 | public IDictionary Param { get; protected set; } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /DapperExtraCRUD/key.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ffhighwind/DapperExtraCRUD/dce70356cc2ee8024777d9e5299034f907b7ed00/DapperExtraCRUD/key.snk -------------------------------------------------------------------------------- /Images/DapperExtraCRUD-200x200.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ffhighwind/DapperExtraCRUD/dce70356cc2ee8024777d9e5299034f907b7ed00/Images/DapperExtraCRUD-200x200.png -------------------------------------------------------------------------------- /Images/DapperExtraCRUD-200x200.xcf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ffhighwind/DapperExtraCRUD/dce70356cc2ee8024777d9e5299034f907b7ed00/Images/DapperExtraCRUD-200x200.xcf -------------------------------------------------------------------------------- /Images/DapperExtraCRUD-500x500.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ffhighwind/DapperExtraCRUD/dce70356cc2ee8024777d9e5299034f907b7ed00/Images/DapperExtraCRUD-500x500.png -------------------------------------------------------------------------------- /Images/DapperExtraCRUD-500x500.xcf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ffhighwind/DapperExtraCRUD/dce70356cc2ee8024777d9e5299034f907b7ed00/Images/DapperExtraCRUD-500x500.xcf -------------------------------------------------------------------------------- /Images/DapperExtraCRUD.xcf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ffhighwind/DapperExtraCRUD/dce70356cc2ee8024777d9e5299034f907b7ed00/Images/DapperExtraCRUD.xcf --------------------------------------------------------------------------------