├── .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