├── .gitignore ├── .nuget ├── NuGet.Config ├── NuGet.exe └── NuGet.targets ├── DapperContext.NET35 ├── DapperContext.NET35.csproj ├── DbConnectionFactory.cs ├── DbContext.cs ├── Properties │ └── AssemblyInfo.cs ├── UnitOfWork.cs └── packages.config ├── DapperContext.NET40 ├── DapperContext.NET40.csproj └── packages.config ├── DapperContext.WpfExample ├── App.config ├── App.xaml ├── App.xaml.cs ├── Converters │ └── NullToVisibilityConverter.cs ├── DapperContext.WpfExample.csproj ├── MainWindow.xaml ├── MainWindow.xaml.cs ├── Messages │ └── CategoryChangedMessage.cs ├── Model │ ├── Category.cs │ ├── Customer.cs │ ├── Employee.cs │ ├── Order.cs │ ├── OrderLine.cs │ └── Product.cs ├── Properties │ ├── AssemblyInfo.cs │ ├── Resources.Designer.cs │ ├── Resources.resx │ ├── Settings.Designer.cs │ └── Settings.settings ├── Repository │ ├── ICategoryRepository.cs │ ├── ICustomerRepository.cs │ ├── IEmployeeRepository.cs │ ├── IOrderRepository.cs │ ├── IProductRepository.cs │ └── Sql │ │ ├── BaseRepository.cs │ │ ├── CategoryRepository.cs │ │ ├── CustomerRepository.cs │ │ ├── EmployeeRepository.cs │ │ ├── OrderRepository.cs │ │ └── ProductRepository.cs ├── Services │ ├── IOrderService.cs │ └── OrderService.cs ├── ViewModel │ ├── CategoryViewModel.cs │ ├── EmployeeViewModel.cs │ ├── MainViewModel.cs │ ├── ProductViewModel.cs │ └── ViewModelLocator.cs └── packages.config ├── DapperContext.nuspec ├── DapperContext.sln ├── LICENSE └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | # Build Folders (you can keep bin if you'd like, to store dlls and pdbs) 2 | [Bb]in/ 3 | [Oo]bj/ 4 | 5 | # mstest test results 6 | TestResults 7 | 8 | ## Ignore Visual Studio temporary files, build results, and 9 | ## files generated by popular Visual Studio add-ons. 10 | 11 | # User-specific files 12 | *.suo 13 | *.user 14 | *.sln.docstates 15 | 16 | # Build results 17 | [Dd]ebug/ 18 | [Rr]elease/ 19 | x64/ 20 | *_i.c 21 | *_p.c 22 | *.ilk 23 | *.meta 24 | *.obj 25 | *.pch 26 | *.pdb 27 | *.pgc 28 | *.pgd 29 | *.rsp 30 | *.sbr 31 | *.tlb 32 | *.tli 33 | *.tlh 34 | *.tmp 35 | *.log 36 | *.vspscc 37 | *.vssscc 38 | .builds 39 | 40 | # Visual C++ cache files 41 | ipch/ 42 | *.aps 43 | *.ncb 44 | *.opensdf 45 | *.sdf 46 | 47 | # Visual Studio profiler 48 | *.psess 49 | *.vsp 50 | *.vspx 51 | 52 | # Guidance Automation Toolkit 53 | *.gpState 54 | 55 | # ReSharper is a .NET coding add-in 56 | _ReSharper* 57 | 58 | # NCrunch 59 | *.ncrunch* 60 | .*crunch*.local.xml 61 | 62 | # Installshield output folder 63 | [Ee]xpress 64 | 65 | # DocProject is a documentation generator add-in 66 | DocProject/buildhelp/ 67 | DocProject/Help/*.HxT 68 | DocProject/Help/*.HxC 69 | DocProject/Help/*.hhc 70 | DocProject/Help/*.hhk 71 | DocProject/Help/*.hhp 72 | DocProject/Help/Html2 73 | DocProject/Help/html 74 | 75 | # Click-Once directory 76 | publish 77 | 78 | # Publish Web Output 79 | *.Publish.xml 80 | 81 | # NuGet Packages Directory 82 | packages 83 | 84 | # Windows Azure Build Output 85 | csx 86 | *.build.csdef 87 | 88 | # Windows Store app package directory 89 | AppPackages/ 90 | 91 | # Others 92 | [Bb]in 93 | [Oo]bj 94 | sql 95 | TestResults 96 | [Tt]est[Rr]esult* 97 | *.Cache 98 | ClientBin 99 | [Ss]tyle[Cc]op.* 100 | ~$* 101 | *.dbmdl 102 | Generated_Code #added for RIA/Silverlight projects 103 | 104 | # Backup & report files from converting an old project file to a newer 105 | # Visual Studio version. Backup files are not needed, because we have git ;-) 106 | _UpgradeReport_Files/ 107 | Backup*/ 108 | UpgradeLog*.XML 109 | 110 | # NuGet related 111 | NuGet.exe 112 | *.nupkg 113 | -------------------------------------------------------------------------------- /.nuget/NuGet.Config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.nuget/NuGet.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wcabus/DapperContext/b16de6bae25ef4ff21e0c11fcee7b5b7815e8558/.nuget/NuGet.exe -------------------------------------------------------------------------------- /.nuget/NuGet.targets: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | $(MSBuildProjectDirectory)\..\ 5 | 6 | 7 | false 8 | 9 | 10 | false 11 | 12 | 13 | true 14 | 15 | 16 | false 17 | 18 | 19 | 20 | 21 | 22 | 26 | 27 | 28 | 29 | 30 | $([System.IO.Path]::Combine($(SolutionDir), ".nuget")) 31 | $([System.IO.Path]::Combine($(ProjectDir), "packages.config")) 32 | 33 | 34 | 35 | 36 | $(SolutionDir).nuget 37 | packages.config 38 | 39 | 40 | 41 | 42 | $(NuGetToolsPath)\NuGet.exe 43 | @(PackageSource) 44 | 45 | "$(NuGetExePath)" 46 | mono --runtime=v4.0.30319 $(NuGetExePath) 47 | 48 | $(TargetDir.Trim('\\')) 49 | 50 | -RequireConsent 51 | -NonInteractive 52 | 53 | "$(SolutionDir) " 54 | "$(SolutionDir)" 55 | 56 | 57 | $(NuGetCommand) install "$(PackagesConfig)" -source "$(PackageSources)" $(NonInteractiveSwitch) $(RequireConsentSwitch) -solutionDir $(PaddedSolutionDir) 58 | $(NuGetCommand) pack "$(ProjectPath)" -Properties "Configuration=$(Configuration);Platform=$(Platform)" $(NonInteractiveSwitch) -OutputDirectory "$(PackageOutputDir)" -symbols 59 | 60 | 61 | 62 | RestorePackages; 63 | $(BuildDependsOn); 64 | 65 | 66 | 67 | 68 | $(BuildDependsOn); 69 | BuildPackage; 70 | 71 | 72 | 73 | 74 | 75 | 76 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 91 | 92 | 95 | 96 | 97 | 98 | 100 | 101 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 133 | 134 | 135 | 136 | -------------------------------------------------------------------------------- /DapperContext.NET35/DapperContext.NET35.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {CBAD325F-3F61-495A-BC28-177FF9CF0A13} 8 | Library 9 | Properties 10 | Dapper 11 | DapperContext 12 | v3.5 13 | 512 14 | 15 | ..\ 16 | true 17 | 18 | 19 | true 20 | full 21 | false 22 | bin\Debug\ 23 | TRACE;DEBUG;CSHARP30 24 | prompt 25 | 4 26 | bin\Debug\DapperContext.XML 27 | 28 | 29 | pdbonly 30 | true 31 | bin\Release\ 32 | TRACE;CSHARP30 33 | prompt 34 | 4 35 | bin\Release\DapperContext.XML 36 | 37 | 38 | 39 | False 40 | ..\packages\Dapper.1.13\lib\net35\Dapper.dll 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 68 | -------------------------------------------------------------------------------- /DapperContext.NET35/DbConnectionFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Configuration; 3 | using System.Data; 4 | using System.Data.Common; 5 | 6 | namespace Dapper 7 | { 8 | /// 9 | /// A DbConnectionFactory allows you to create instances by configuring 10 | /// a connection in the connectionstrings section inside a app/web.config file. 11 | /// 12 | public class DbConnectionFactory 13 | { 14 | private readonly DbProviderFactory _provider; 15 | private readonly string _connectionString; 16 | private readonly string _name; 17 | 18 | /// 19 | /// Creates a new DbConnectionFactory instance. 20 | /// 21 | /// A key of one of the connectionstring settings inside the connectionstrings section of an app/web.config file. 22 | /// Thrown if is a null value.4 23 | /// Thrown if is not found in any app/web.config file available to the application. 24 | public DbConnectionFactory(string connectionStringName) 25 | { 26 | if (connectionStringName == null) throw new ArgumentNullException("connectionStringName"); 27 | 28 | var conStr = ConfigurationManager.ConnectionStrings[connectionStringName]; 29 | if (conStr == null) 30 | throw new ConfigurationErrorsException( 31 | string.Format("Failed to find connection string named '{0}' in app.config or web.config.", connectionStringName)); 32 | 33 | _name = conStr.ProviderName; 34 | _provider = DbProviderFactories.GetFactory(conStr.ProviderName); 35 | _connectionString = conStr.ConnectionString; 36 | } 37 | 38 | /// 39 | /// Creates a new instance of . 40 | /// 41 | /// Thrown if the connectionstring entry in the app/web.config file is missing information, contains errors or is missing entirely. 42 | /// 43 | public IDbConnection Create() 44 | { 45 | var connection = _provider.CreateConnection(); 46 | if (connection == null) 47 | throw new ConfigurationErrorsException( 48 | string.Format( 49 | "Failed to create a connection using the connection string named '{0}' in app.config or web.config.", 50 | _name)); 51 | 52 | connection.ConnectionString = _connectionString; 53 | return connection; 54 | } 55 | } 56 | } -------------------------------------------------------------------------------- /DapperContext.NET35/DbContext.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Data; 4 | using System.Linq; 5 | using System.Threading; 6 | 7 | namespace Dapper 8 | { 9 | /// 10 | /// A database context class for Dapper (https://github.com/SamSaffron/dapper-dot-net), based on http://blog.gauffin.org/2013/01/ado-net-the-right-way/#.UpWLPMSkrd2 11 | /// 12 | public class DbContext : IDisposable 13 | { 14 | private IDbConnection _connection; 15 | private readonly DbConnectionFactory _connectionFactory; 16 | private readonly ReaderWriterLockSlim _rwLock = new ReaderWriterLockSlim(); 17 | private readonly LinkedList _workItems = new LinkedList(); 18 | 19 | /// 20 | /// Default constructor. 21 | /// Uses the to instantiate a . This factory will be used to create connections to a database. 22 | /// 23 | /// The name of the connectionstring as defined in a app/web.config file's connectionstrings section. 24 | public DbContext(string connectionStringName) 25 | { 26 | _connectionFactory = new DbConnectionFactory(connectionStringName); 27 | } 28 | 29 | /// 30 | /// Ensures that a connection is ready for querying or creating transactions 31 | /// 32 | /// 33 | private void CreateOrReuseConnection() 34 | { 35 | if (_connection != null) return; 36 | 37 | _connection = _connectionFactory.Create(); 38 | } 39 | 40 | /// 41 | /// Creates a new . 42 | /// 43 | /// The used for the transaction inside this unit of work. Default value: 44 | /// 45 | public UnitOfWork CreateUnitOfWork(IsolationLevel isolationLevel = IsolationLevel.ReadCommitted) 46 | { 47 | CreateOrReuseConnection(); 48 | 49 | //To create a transaction, our connection needs to be open. 50 | //If we need to open the connection ourselves, we're also in charge of closing it when this transaction commits or rolls back. 51 | //This will be done by RemoveTransactionAndCloseConnection in that case. 52 | bool wasClosed = _connection.State == ConnectionState.Closed; 53 | if (wasClosed) _connection.Open(); 54 | 55 | try 56 | { 57 | UnitOfWork unit; 58 | IDbTransaction transaction = _connection.BeginTransaction(isolationLevel); 59 | 60 | if (wasClosed) 61 | unit = new UnitOfWork(transaction, RemoveTransactionAndCloseConnection, RemoveTransactionAndCloseConnection); 62 | else 63 | unit = new UnitOfWork(transaction, RemoveTransaction, RemoveTransaction); 64 | 65 | _rwLock.EnterWriteLock(); 66 | _workItems.AddLast(unit); 67 | _rwLock.ExitWriteLock(); 68 | 69 | return unit; 70 | } 71 | catch 72 | { 73 | //Close the connection if we're managing it, and if an exception is thrown when creating the transaction. 74 | if (wasClosed) _connection.Close(); 75 | 76 | throw; //Rethrow the original transaction 77 | } 78 | } 79 | 80 | private IDbTransaction GetCurrentTransaction() 81 | { 82 | IDbTransaction currentTransaction = null; 83 | _rwLock.EnterReadLock(); 84 | if (_workItems.Any()) currentTransaction = _workItems.First.Value.Transaction; 85 | _rwLock.ExitReadLock(); 86 | 87 | return currentTransaction; 88 | } 89 | 90 | #if !CSHARP30 91 | /// 92 | /// Return a list of dynamic objects, reader is closed after the call 93 | /// 94 | public IEnumerable Query(string sql, dynamic param = null, int? commandTimeout = null, CommandType? commandType = null) 95 | { 96 | CreateOrReuseConnection(); 97 | //Dapper will open and close the connection for us if necessary. 98 | return SqlMapper.Query(_connection, sql, param, GetCurrentTransaction(), true, commandTimeout, commandType); 99 | } 100 | #else 101 | /// 102 | /// Return a list of dynamic objects, reader is closed after the call 103 | /// 104 | public IEnumerable> Query(string sql, object param) 105 | { 106 | return Query(sql, param, null, null); 107 | } 108 | 109 | /// 110 | /// Return a list of dynamic objects, reader is closed after the call 111 | /// 112 | public IEnumerable> Query(string sql, object param, CommandType? commandType) 113 | { 114 | return Query(sql, param, null, commandType); 115 | } 116 | 117 | /// 118 | /// Return a list of dynamic objects, reader is closed after the call 119 | /// 120 | public IEnumerable> Query(string sql, object param, int? commandTimeout, CommandType? commandType) 121 | { 122 | CreateOrReuseConnection(); 123 | //Dapper will open and close the connection for us if necessary. 124 | return _connection.Query(sql, param, GetCurrentTransaction(), true, commandTimeout, commandType); 125 | } 126 | #endif 127 | 128 | #if CSHARP30 129 | /// 130 | /// Execute parameterized SQL 131 | /// 132 | /// Number of rows affected 133 | public int Execute(string sql, object param) 134 | { 135 | return Execute(sql, param, null, null); 136 | } 137 | 138 | /// 139 | /// Execute parameterized SQL 140 | /// 141 | /// Number of rows affected 142 | public int Execute(string sql, object param, CommandType commandType) 143 | { 144 | return Execute(sql, param, null, commandType); 145 | } 146 | 147 | /// 148 | /// Executes a query, returning the data typed as per T 149 | /// 150 | /// A sequence of data of the supplied type; if a basic type (int, string, etc) is queried then the data from the first column in assumed, otherwise an instance is 151 | /// created per row, and a direct column-name===member-name mapping is assumed (case insensitive). 152 | /// 153 | public IEnumerable Query(string sql, object param) 154 | { 155 | return Query(sql, param, null, null); 156 | } 157 | 158 | /// 159 | /// Executes a query, returning the data typed as per T 160 | /// 161 | /// A sequence of data of the supplied type; if a basic type (int, string, etc) is queried then the data from the first column in assumed, otherwise an instance is 162 | /// created per row, and a direct column-name===member-name mapping is assumed (case insensitive). 163 | /// 164 | public IEnumerable Query(string sql, object param, CommandType commandType) 165 | { 166 | return Query(sql, param, null, commandType); 167 | } 168 | 169 | /// 170 | /// Execute a command that returns multiple result sets, and access each in turn 171 | /// 172 | public SqlMapper.GridReader QueryMultiple(string sql, object param) 173 | { 174 | return QueryMultiple(sql, param, null, null); 175 | } 176 | 177 | /// 178 | /// Execute a command that returns multiple result sets, and access each in turn 179 | /// 180 | public SqlMapper.GridReader QueryMultiple(string sql, object param, CommandType commandType) 181 | { 182 | return QueryMultiple(sql, param, null, commandType); 183 | } 184 | #endif 185 | 186 | #if CSHARP30 187 | public IEnumerable Query(string sql, object param, int? commandTimeout, CommandType? commandType) 188 | #else 189 | public IEnumerable Query(string sql, dynamic param = null, int? commandTimeout = null, CommandType? commandType = null) 190 | #endif 191 | { 192 | CreateOrReuseConnection(); 193 | //Dapper will open and close the connection for us if necessary. 194 | return SqlMapper.Query(_connection, sql, param, GetCurrentTransaction(), true, commandTimeout, commandType); 195 | } 196 | 197 | #if CSHARP30 198 | public IEnumerable Query(string sql, Func map, object param, string splitOn, int? commandTimeout, CommandType? commandType) 199 | #else 200 | public IEnumerable Query(string sql, Func map, dynamic param = null, string splitOn = "Id", int? commandTimeout = null, CommandType? commandType = null) 201 | #endif 202 | { 203 | CreateOrReuseConnection(); 204 | //Dapper will open and close the connection for us if necessary. 205 | return SqlMapper.Query(_connection, sql, map, param, GetCurrentTransaction(), true, splitOn, commandTimeout, commandType); 206 | } 207 | 208 | #if CSHARP30 209 | public IEnumerable Query(string sql, Func map, object param, string splitOn, int? commandTimeout, CommandType? commandType) 210 | #else 211 | public IEnumerable Query(string sql, Func map, dynamic param = null, string splitOn = "Id", int? commandTimeout = null, CommandType? commandType = null) 212 | #endif 213 | { 214 | CreateOrReuseConnection(); 215 | //Dapper will open and close the connection for us if necessary. 216 | return SqlMapper.Query(_connection, sql, map, param, GetCurrentTransaction(), true, splitOn, commandTimeout, commandType); 217 | } 218 | 219 | #if CSHARP30 220 | public IEnumerable Query(string sql, Func map, object param, string splitOn, int? commandTimeout, CommandType? commandType) 221 | #else 222 | public IEnumerable Query(string sql, Func map, dynamic param = null, string splitOn = "Id", int? commandTimeout = null, CommandType? commandType = null) 223 | #endif 224 | { 225 | CreateOrReuseConnection(); 226 | //Dapper will open and close the connection for us if necessary. 227 | return SqlMapper.Query(_connection, sql, map, param, GetCurrentTransaction(), true, splitOn, commandTimeout, commandType); 228 | } 229 | 230 | #if !CSHARP30 231 | public IEnumerable Query(string sql, Func map, dynamic param = null, string splitOn = "Id", int? commandTimeout = null, CommandType? commandType = null) 232 | { 233 | CreateOrReuseConnection(); 234 | //Dapper will open and close the connection for us if necessary. 235 | return SqlMapper.Query(_connection, sql, map, param, GetCurrentTransaction(), true, splitOn, commandTimeout, commandType); 236 | } 237 | 238 | public IEnumerable Query(string sql, Func map, dynamic param = null, string splitOn = "Id", int? commandTimeout = null, CommandType? commandType = null) 239 | { 240 | CreateOrReuseConnection(); 241 | //Dapper will open and close the connection for us if necessary. 242 | return SqlMapper.Query(_connection, sql, map, param, GetCurrentTransaction(), true, splitOn, commandTimeout, commandType); 243 | } 244 | 245 | public IEnumerable Query(string sql, Func map, dynamic param = null, string splitOn = "Id", int? commandTimeout = null, CommandType? commandType = null) 246 | { 247 | CreateOrReuseConnection(); 248 | //Dapper will open and close the connection for us if necessary. 249 | return SqlMapper.Query(_connection, sql, map, param, GetCurrentTransaction(), true, splitOn, commandTimeout, commandType); 250 | } 251 | #endif 252 | 253 | #if CSHARP30 254 | public SqlMapper.GridReader QueryMultiple(string sql, object param, int? commandTimeout, CommandType? commandType) 255 | #else 256 | public SqlMapper.GridReader QueryMultiple(string sql, dynamic param = null, int? commandTimeout = null, CommandType? commandType = null) 257 | #endif 258 | { 259 | CreateOrReuseConnection(); 260 | //Dapper will open and close the connection for us if necessary. 261 | return SqlMapper.QueryMultiple(_connection, sql, param, GetCurrentTransaction(), commandTimeout, commandType); 262 | } 263 | 264 | #if CSHARP30 265 | public int Execute(string sql, object param, int? commandTimeout, CommandType? commandType) 266 | #else 267 | public int Execute(string sql, dynamic param = null, int? commandTimeout = null, CommandType? commandType = null) 268 | #endif 269 | { 270 | CreateOrReuseConnection(); 271 | //Dapper expects a connection to be open when calling Execute, so we'll have to open it. 272 | bool wasClosed = _connection.State == ConnectionState.Closed; 273 | if (wasClosed) _connection.Open(); 274 | try 275 | { 276 | return SqlMapper.Execute(_connection, sql, param, GetCurrentTransaction(), commandTimeout, commandType); 277 | } 278 | finally 279 | { 280 | if (wasClosed) _connection.Close(); 281 | } 282 | } 283 | 284 | private void RemoveTransaction(UnitOfWork workItem) 285 | { 286 | _rwLock.EnterWriteLock(); 287 | _workItems.Remove(workItem); 288 | _rwLock.ExitWriteLock(); 289 | } 290 | 291 | private void RemoveTransactionAndCloseConnection(UnitOfWork workItem) 292 | { 293 | _rwLock.EnterWriteLock(); 294 | _workItems.Remove(workItem); 295 | _rwLock.ExitWriteLock(); 296 | 297 | _connection.Close(); 298 | } 299 | 300 | /// 301 | /// Implements . 302 | /// 303 | public void Dispose() 304 | { 305 | //Use an upgradeable lock, because when we dispose a unit of work, 306 | //one of the removal methods will be called (which enters a write lock) 307 | _rwLock.EnterUpgradeableReadLock(); 308 | try 309 | { 310 | while (_workItems.Any()) 311 | { 312 | var workItem = _workItems.First; 313 | workItem.Value.Dispose(); //rollback, will remove the item from the LinkedList because it calls either RemoveTransaction or RemoveTransactionAndCloseConnection 314 | } 315 | } 316 | finally 317 | { 318 | _rwLock.ExitUpgradeableReadLock(); 319 | } 320 | 321 | if (_connection != null) 322 | { 323 | _connection.Dispose(); 324 | _connection = null; 325 | } 326 | } 327 | } 328 | } 329 | -------------------------------------------------------------------------------- /DapperContext.NET35/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("DapperContext")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("Wesley Cabus")] 12 | [assembly: AssemblyProduct("DapperContext")] 13 | [assembly: AssemblyCopyright("Copyright © Wesley Cabus 2013")] 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("c6e64879-3f7d-43ec-96ae-f66cea13c005")] 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("0.1.*")] 36 | [assembly: AssemblyFileVersion("0.1.1.0")] 37 | -------------------------------------------------------------------------------- /DapperContext.NET35/UnitOfWork.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Data; 3 | 4 | namespace Dapper 5 | { 6 | /// 7 | /// This class defines a unit of work, which encapsulates a set of operations that should 8 | /// be committed as a whole, or rolled back in case one of the statements inside the unit of work fails. 9 | /// 10 | public class UnitOfWork : IDisposable 11 | { 12 | private IDbTransaction _transaction; 13 | private readonly Action _onCommit; 14 | private readonly Action _onRollback; 15 | 16 | /// 17 | /// Creates a new instance. 18 | /// 19 | /// The underlying object used to either commit or roll back the statements that are being performed inside this unit of work. 20 | /// An that will be executed when the unit of work is being committed or rolled back. 21 | public UnitOfWork(IDbTransaction transaction, Action onCommitOrRollback) : this(transaction, onCommitOrRollback, onCommitOrRollback) 22 | { 23 | } 24 | 25 | /// 26 | /// Creates a new instance. 27 | /// 28 | /// The underlying object used to either commit or roll back the statements that are being performed inside this unit of work. 29 | /// An that will be executed when the unit of work is being committed. 30 | /// An that will be executed when the unit of work is being rolled back. 31 | public UnitOfWork(IDbTransaction transaction, Action onCommit, Action onRollback) 32 | { 33 | _transaction = transaction; 34 | _onCommit = onCommit; 35 | _onRollback = onRollback; 36 | } 37 | 38 | /// 39 | /// Retrieves the underlying instance. 40 | /// 41 | public IDbTransaction Transaction 42 | { 43 | get { return _transaction; } 44 | } 45 | 46 | /// 47 | /// SaveChanges will try and commit all statements that have been executed against the database inside this unit of work. 48 | /// 49 | /// 50 | /// If committing fails, the underlying will be rolled back instead. 51 | /// 52 | /// Thrown if this unit of work has already been committed or rolled back. 53 | public void SaveChanges() 54 | { 55 | if (_transaction == null) 56 | throw new InvalidOperationException("This unit of work has already been saved or undone."); 57 | 58 | try { 59 | _transaction.Commit(); 60 | _onCommit(this); 61 | } 62 | finally 63 | { 64 | _transaction.Dispose(); 65 | _transaction = null; 66 | } 67 | } 68 | 69 | /// 70 | /// Implements , and rolls back the statements executed inside this unit of work. 71 | /// This makes it easier to use a unit of work instance inside a using statement (Using in VB.Net). 72 | /// 73 | public void Dispose() 74 | { 75 | if (_transaction == null) return; 76 | 77 | try 78 | { 79 | _transaction.Rollback(); 80 | _onRollback(this); 81 | } 82 | finally 83 | { 84 | _transaction.Dispose(); 85 | _transaction = null; 86 | } 87 | } 88 | } 89 | } -------------------------------------------------------------------------------- /DapperContext.NET35/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /DapperContext.NET40/DapperContext.NET40.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {2224F63F-3D00-4E24-A38A-86DE147E1A5A} 8 | Library 9 | Properties 10 | Dapper 11 | DapperContext 12 | v4.0 13 | 512 14 | ..\ 15 | true 16 | 17 | 18 | true 19 | full 20 | false 21 | bin\Debug\ 22 | DEBUG;TRACE 23 | prompt 24 | 4 25 | bin\Debug\DapperContext.XML 26 | 27 | 28 | pdbonly 29 | true 30 | bin\Release\ 31 | TRACE 32 | prompt 33 | 4 34 | bin\Release\DapperContext.XML 35 | 36 | 37 | 38 | False 39 | ..\packages\Dapper.1.13\lib\net40\Dapper.dll 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | DbConnectionFactory.cs 53 | 54 | 55 | DbContext.cs 56 | 57 | 58 | AssemblyInfo.cs 59 | 60 | 61 | UnitOfWork.cs 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | Designer 70 | 71 | 72 | 73 | 74 | 81 | -------------------------------------------------------------------------------- /DapperContext.NET40/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /DapperContext.WpfExample/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 7 | 8 | 9 | 11 | 12 | -------------------------------------------------------------------------------- /DapperContext.WpfExample/App.xaml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /DapperContext.WpfExample/App.xaml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Configuration; 4 | using System.Data; 5 | using System.Linq; 6 | using System.Windows; 7 | 8 | namespace DapperContext.WpfExample 9 | { 10 | /// 11 | /// Interaction logic for App.xaml 12 | /// 13 | public partial class App : Application 14 | { 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /DapperContext.WpfExample/Converters/NullToVisibilityConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Globalization; 3 | using System.Windows; 4 | using System.Windows.Data; 5 | 6 | namespace DapperContext.WpfExample.Converters 7 | { 8 | public class NullToVisibilityConverter : IValueConverter 9 | { 10 | public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 11 | { 12 | return value == null ? Visibility.Collapsed : Visibility.Visible; 13 | } 14 | 15 | public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 16 | { 17 | throw new NotImplementedException(); 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /DapperContext.WpfExample/DapperContext.WpfExample.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {B85ED38C-5EAE-4EDF-A2A2-CFA7FD40B519} 8 | WinExe 9 | Properties 10 | DapperContext.WpfExample 11 | DapperContext.WpfExample 12 | v4.0 13 | 512 14 | {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 15 | 4 16 | ..\ 17 | true 18 | 19 | 20 | AnyCPU 21 | true 22 | full 23 | false 24 | bin\Debug\ 25 | DEBUG;TRACE 26 | prompt 27 | 4 28 | 29 | 30 | AnyCPU 31 | pdbonly 32 | true 33 | bin\Release\ 34 | TRACE 35 | prompt 36 | 4 37 | 38 | 39 | 40 | False 41 | ..\packages\Dapper.1.13\lib\net40\Dapper.dll 42 | 43 | 44 | False 45 | ..\packages\DapperContext.0.1.2-alpha\lib\net40\DapperContext.dll 46 | 47 | 48 | ..\packages\MvvmLightLibs.4.2.30.0\lib\net40\GalaSoft.MvvmLight.Extras.WPF4.dll 49 | 50 | 51 | ..\packages\MvvmLightLibs.4.2.30.0\lib\net40\GalaSoft.MvvmLight.WPF4.dll 52 | 53 | 54 | ..\packages\CommonServiceLocator.1.0\lib\NET35\Microsoft.Practices.ServiceLocation.dll 55 | 56 | 57 | 58 | 59 | 60 | ..\packages\MvvmLightLibs.4.2.30.0\lib\net40\System.Windows.Interactivity.dll 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 4.0 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | MSBuild:Compile 77 | Designer 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | MSBuild:Compile 107 | Designer 108 | 109 | 110 | App.xaml 111 | Code 112 | 113 | 114 | MainWindow.xaml 115 | Code 116 | 117 | 118 | 119 | 120 | Code 121 | 122 | 123 | True 124 | True 125 | Resources.resx 126 | 127 | 128 | True 129 | Settings.settings 130 | True 131 | 132 | 133 | ResXFileCodeGenerator 134 | Resources.Designer.cs 135 | 136 | 137 | 138 | 139 | SettingsSingleFileGenerator 140 | Settings.Designer.cs 141 | 142 | 143 | 144 | 145 | 146 | 147 | 154 | -------------------------------------------------------------------------------- /DapperContext.WpfExample/MainWindow.xaml: -------------------------------------------------------------------------------- 1 |  7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | Categories 19 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | Products 37 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | Your order currently contains item(s). 55 | 56 | 57 | 58 | 59 | Product Details 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | Name: 72 | 73 | Price: 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | -------------------------------------------------------------------------------- /DapperContext.WpfExample/MainWindow.xaml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Windows; 6 | using System.Windows.Controls; 7 | using System.Windows.Data; 8 | using System.Windows.Documents; 9 | using System.Windows.Input; 10 | using System.Windows.Media; 11 | using System.Windows.Media.Imaging; 12 | using System.Windows.Navigation; 13 | using System.Windows.Shapes; 14 | 15 | namespace DapperContext.WpfExample 16 | { 17 | /// 18 | /// Interaction logic for MainWindow.xaml 19 | /// 20 | public partial class MainWindow : Window 21 | { 22 | public MainWindow() 23 | { 24 | InitializeComponent(); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /DapperContext.WpfExample/Messages/CategoryChangedMessage.cs: -------------------------------------------------------------------------------- 1 | using DapperContext.WpfExample.Model; 2 | using GalaSoft.MvvmLight.Messaging; 3 | 4 | namespace DapperContext.WpfExample.Messages 5 | { 6 | public class CategoryChangedMessage : MessageBase 7 | { 8 | public CategoryChangedMessage(Category category) 9 | { 10 | Category = category; 11 | } 12 | 13 | public Category Category { get; private set; } 14 | } 15 | } -------------------------------------------------------------------------------- /DapperContext.WpfExample/Model/Category.cs: -------------------------------------------------------------------------------- 1 | namespace DapperContext.WpfExample.Model 2 | { 3 | public class Category 4 | { 5 | public int CategoryID { get; set; } 6 | public string CategoryName { get; set; } 7 | public string Description { get; set; } 8 | } 9 | } -------------------------------------------------------------------------------- /DapperContext.WpfExample/Model/Customer.cs: -------------------------------------------------------------------------------- 1 | namespace DapperContext.WpfExample.Model 2 | { 3 | public class Customer 4 | { 5 | public string CustomerID { get; set; } 6 | public string CompanyName { get; set; } 7 | public string ContactName { get; set; } 8 | public string ContactTitle { get; set; } 9 | public string Address { get; set; } 10 | public string City { get; set; } 11 | public string Region { get; set; } 12 | public string PostalCode { get; set; } 13 | public string Country { get; set; } 14 | public string Phone { get; set; } 15 | public string Fax { get; set; } 16 | } 17 | } -------------------------------------------------------------------------------- /DapperContext.WpfExample/Model/Employee.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace DapperContext.WpfExample.Model 4 | { 5 | public class Employee 6 | { 7 | public int EmployeeID { get; set; } 8 | public string LastName { get; set; } 9 | public string FirstName { get; set; } 10 | public string Title { get; set; } 11 | public string TitleOfCourtesy { get; set; } 12 | public DateTime? BirthDate { get; set; } 13 | public DateTime? HireDate { get; set; } 14 | public string Address { get; set; } 15 | public string City { get; set; } 16 | public string Region { get; set; } 17 | public string PostalCode { get; set; } 18 | public string Country { get; set; } 19 | public string HomePhone { get; set; } 20 | public string Extension { get; set; } 21 | } 22 | } -------------------------------------------------------------------------------- /DapperContext.WpfExample/Model/Order.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | 5 | namespace DapperContext.WpfExample.Model 6 | { 7 | public class Order 8 | { 9 | public int OrderID { get; set; } 10 | public string CustomerID { get; set; } 11 | public int? EmployeeID { get; set; } 12 | public DateTime? OrderDate { get; set; } 13 | public DateTime? RequiredDate { get; set; } 14 | public DateTime? ShippedDate { get; set; } 15 | public decimal? Freight { get; set; } 16 | public string ShipName { get; set; } 17 | public string ShipAddress { get; set; } 18 | public string ShipCity { get; set; } 19 | public string ShipRegion { get; set; } 20 | public string ShipPostalCode { get; set; } 21 | public string ShipCountry { get; set; } 22 | 23 | public ICollection Lines { get; set; } 24 | } 25 | } -------------------------------------------------------------------------------- /DapperContext.WpfExample/Model/OrderLine.cs: -------------------------------------------------------------------------------- 1 | namespace DapperContext.WpfExample.Model 2 | { 3 | public class OrderLine 4 | { 5 | public int OrderID { get; set; } 6 | public int ProductID { get; set; } 7 | public decimal UnitPrice { get; set; } 8 | public short Quantity { get; set; } 9 | public float Discount { get; set; } 10 | } 11 | } -------------------------------------------------------------------------------- /DapperContext.WpfExample/Model/Product.cs: -------------------------------------------------------------------------------- 1 | namespace DapperContext.WpfExample.Model 2 | { 3 | public class Product 4 | { 5 | public int ProductID { get; set; } 6 | public string ProductName { get; set; } 7 | public int? SupplierID { get; set; } 8 | public int? CategoryID { get; set; } 9 | public string QuantityPerUnit { get; set; } 10 | public decimal? UnitPrice { get; set; } 11 | public short? UnitsInStock { get; set; } 12 | public short? UnitsOnOrder { get; set; } 13 | public short? ReorderLevel { get; set; } 14 | public bool Discontinued { get; set; } 15 | } 16 | } -------------------------------------------------------------------------------- /DapperContext.WpfExample/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Resources; 3 | using System.Runtime.CompilerServices; 4 | using System.Runtime.InteropServices; 5 | using System.Windows; 6 | 7 | // General Information about an assembly is controlled through the following 8 | // set of attributes. Change these attribute values to modify the information 9 | // associated with an assembly. 10 | [assembly: AssemblyTitle("DapperContext.WpfExample")] 11 | [assembly: AssemblyDescription("")] 12 | [assembly: AssemblyConfiguration("")] 13 | [assembly: AssemblyCompany("")] 14 | [assembly: AssemblyProduct("DapperContext.WpfExample")] 15 | [assembly: AssemblyCopyright("Copyright © 2014")] 16 | [assembly: AssemblyTrademark("")] 17 | [assembly: AssemblyCulture("")] 18 | 19 | // Setting ComVisible to false makes the types in this assembly not visible 20 | // to COM components. If you need to access a type in this assembly from 21 | // COM, set the ComVisible attribute to true on that type. 22 | [assembly: ComVisible(false)] 23 | 24 | //In order to begin building localizable applications, set 25 | //CultureYouAreCodingWith in your .csproj file 26 | //inside a . For example, if you are using US english 27 | //in your source files, set the to en-US. Then uncomment 28 | //the NeutralResourceLanguage attribute below. Update the "en-US" in 29 | //the line below to match the UICulture setting in the project file. 30 | 31 | //[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)] 32 | 33 | 34 | [assembly: ThemeInfo( 35 | ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located 36 | //(used if a resource is not found in the page, 37 | // or application resource dictionaries) 38 | ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located 39 | //(used if a resource is not found in the page, 40 | // app, or any theme specific resource dictionaries) 41 | )] 42 | 43 | 44 | // Version information for an assembly consists of the following four values: 45 | // 46 | // Major Version 47 | // Minor Version 48 | // Build Number 49 | // Revision 50 | // 51 | // You can specify all the values or you can default the Build and Revision Numbers 52 | // by using the '*' as shown below: 53 | // [assembly: AssemblyVersion("1.0.*")] 54 | [assembly: AssemblyVersion("1.0.0.0")] 55 | [assembly: AssemblyFileVersion("1.0.0.0")] 56 | -------------------------------------------------------------------------------- /DapperContext.WpfExample/Properties/Resources.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.34003 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace DapperContext.WpfExample.Properties 12 | { 13 | 14 | 15 | /// 16 | /// A strongly-typed resource class, for looking up localized strings, etc. 17 | /// 18 | // This class was auto-generated by the StronglyTypedResourceBuilder 19 | // class via a tool like ResGen or Visual Studio. 20 | // To add or remove a member, edit your .ResX file then rerun ResGen 21 | // with the /str option, or rebuild your VS project. 22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] 23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 25 | internal class Resources 26 | { 27 | 28 | private static global::System.Resources.ResourceManager resourceMan; 29 | 30 | private static global::System.Globalization.CultureInfo resourceCulture; 31 | 32 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 33 | internal Resources() 34 | { 35 | } 36 | 37 | /// 38 | /// Returns the cached ResourceManager instance used by this class. 39 | /// 40 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 41 | internal static global::System.Resources.ResourceManager ResourceManager 42 | { 43 | get 44 | { 45 | if ((resourceMan == null)) 46 | { 47 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("DapperContext.WpfExample.Properties.Resources", typeof(Resources).Assembly); 48 | resourceMan = temp; 49 | } 50 | return resourceMan; 51 | } 52 | } 53 | 54 | /// 55 | /// Overrides the current thread's CurrentUICulture property for all 56 | /// resource lookups using this strongly typed resource class. 57 | /// 58 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 59 | internal static global::System.Globalization.CultureInfo Culture 60 | { 61 | get 62 | { 63 | return resourceCulture; 64 | } 65 | set 66 | { 67 | resourceCulture = value; 68 | } 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /DapperContext.WpfExample/Properties/Resources.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 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 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | text/microsoft-resx 107 | 108 | 109 | 2.0 110 | 111 | 112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 113 | 114 | 115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | -------------------------------------------------------------------------------- /DapperContext.WpfExample/Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.34003 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace DapperContext.WpfExample.Properties 12 | { 13 | 14 | 15 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 16 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] 17 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase 18 | { 19 | 20 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 21 | 22 | public static Settings Default 23 | { 24 | get 25 | { 26 | return defaultInstance; 27 | } 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /DapperContext.WpfExample/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /DapperContext.WpfExample/Repository/ICategoryRepository.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using DapperContext.WpfExample.Model; 4 | 5 | namespace DapperContext.WpfExample.Repository 6 | { 7 | public interface ICategoryRepository 8 | { 9 | IEnumerable GetCategories(); 10 | } 11 | } -------------------------------------------------------------------------------- /DapperContext.WpfExample/Repository/ICustomerRepository.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using DapperContext.WpfExample.Model; 4 | 5 | namespace DapperContext.WpfExample.Repository 6 | { 7 | public interface ICustomerRepository 8 | { 9 | IEnumerable GetCustomers(); 10 | Customer GetCustomer(string customerID); 11 | } 12 | } -------------------------------------------------------------------------------- /DapperContext.WpfExample/Repository/IEmployeeRepository.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using DapperContext.WpfExample.Model; 4 | 5 | namespace DapperContext.WpfExample.Repository 6 | { 7 | public interface IEmployeeRepository 8 | { 9 | IEnumerable GetEmployees(); 10 | Employee GetEmployee(int employeeID); 11 | } 12 | } -------------------------------------------------------------------------------- /DapperContext.WpfExample/Repository/IOrderRepository.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using DapperContext.WpfExample.Model; 4 | 5 | namespace DapperContext.WpfExample.Repository 6 | { 7 | public interface IOrderRepository 8 | { 9 | IEnumerable GetCustomerOrders(Customer customer); 10 | IEnumerable GetOrderDetail(Order order); 11 | 12 | } 13 | } -------------------------------------------------------------------------------- /DapperContext.WpfExample/Repository/IProductRepository.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using DapperContext.WpfExample.Model; 4 | 5 | namespace DapperContext.WpfExample.Repository 6 | { 7 | public interface IProductRepository 8 | { 9 | IEnumerable GetProducts(); 10 | IEnumerable GetProducts(string name); 11 | IEnumerable GetProductsByCategory(Category category); 12 | Product GetProduct(int productID); 13 | } 14 | } -------------------------------------------------------------------------------- /DapperContext.WpfExample/Repository/Sql/BaseRepository.cs: -------------------------------------------------------------------------------- 1 | using System.Configuration; 2 | using Dapper; 3 | 4 | namespace DapperContext.WpfExample.Repository.Sql 5 | { 6 | public abstract class BaseRepository 7 | { 8 | protected DbContext CreateContext() 9 | { 10 | return new DbContext(ConfigurationManager.AppSettings["Database"]); 11 | } 12 | } 13 | } -------------------------------------------------------------------------------- /DapperContext.WpfExample/Repository/Sql/CategoryRepository.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using Dapper; 3 | using DapperContext.WpfExample.Model; 4 | 5 | namespace DapperContext.WpfExample.Repository.Sql 6 | { 7 | public class CategoryRepository : BaseRepository, ICategoryRepository 8 | { 9 | public IEnumerable GetCategories() 10 | { 11 | return CreateContext().Query("SELECT * FROM Categories"); 12 | } 13 | } 14 | } -------------------------------------------------------------------------------- /DapperContext.WpfExample/Repository/Sql/CustomerRepository.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using Dapper; 4 | using DapperContext.WpfExample.Model; 5 | 6 | namespace DapperContext.WpfExample.Repository.Sql 7 | { 8 | public class CustomerRepository : BaseRepository, ICustomerRepository 9 | { 10 | public IEnumerable GetCustomers() 11 | { 12 | return CreateContext().Query("SELECT * FROM Customers"); 13 | } 14 | 15 | public Customer GetCustomer(string customerID) 16 | { 17 | return CreateContext().Query("SELECT * FROM Customers WHERE CustomerID = @CustomerID", new {customerID}).SingleOrDefault(); 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /DapperContext.WpfExample/Repository/Sql/EmployeeRepository.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Data.Common; 3 | using System.Linq; 4 | using Dapper; 5 | using DapperContext.WpfExample.Model; 6 | 7 | namespace DapperContext.WpfExample.Repository.Sql 8 | { 9 | public class EmployeeRepository : BaseRepository, IEmployeeRepository 10 | { 11 | public IEnumerable GetEmployees() 12 | { 13 | return CreateContext().Query("SELECT * FROM Employees"); 14 | } 15 | 16 | public Employee GetEmployee(int employeeID) 17 | { 18 | return CreateContext().Query("SELECT * FROM Employees WHERE EmployeeID = @EmployeeID", new {employeeID}).SingleOrDefault(); 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /DapperContext.WpfExample/Repository/Sql/OrderRepository.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using Dapper; 3 | using DapperContext.WpfExample.Model; 4 | 5 | namespace DapperContext.WpfExample.Repository.Sql 6 | { 7 | public class OrderRepository : BaseRepository, IOrderRepository 8 | { 9 | public IEnumerable GetCustomerOrders(Customer customer) 10 | { 11 | return CreateContext().Query("SELECT * FROM Orders WHERE CustomerID = @CustomerID", new {customer.CustomerID}); 12 | } 13 | 14 | public IEnumerable GetOrderDetail(Order order) 15 | { 16 | return CreateContext().Query("SELECT * FROM [Order Details] WHERE OrderID = @OrderID", 17 | new {order.OrderID}); 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /DapperContext.WpfExample/Repository/Sql/ProductRepository.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using Dapper; 4 | using DapperContext.WpfExample.Model; 5 | 6 | namespace DapperContext.WpfExample.Repository.Sql 7 | { 8 | public class ProductRepository : BaseRepository, IProductRepository 9 | { 10 | public IEnumerable GetProducts() 11 | { 12 | return CreateContext().Query("SELECT * FROM Products"); 13 | } 14 | 15 | public IEnumerable GetProducts(string name) 16 | { 17 | name = name.Replace("*", "%"); //SQL Server uses % as a wildcard instead of the more commonly used * 18 | return CreateContext().Query("SELECT * FROM Products WHERE ProductName LIKE @Name", new {name}); 19 | } 20 | 21 | public IEnumerable GetProductsByCategory(Category category) 22 | { 23 | return CreateContext().Query("SELECT * FROM Products WHERE CategoryID = @CategoryID", new { category.CategoryID }); 24 | } 25 | 26 | public Product GetProduct(int productID) 27 | { 28 | return CreateContext().Query("SELECT * FROM Products WHERE ProductID = @ProductID", new {productID}).SingleOrDefault(); 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /DapperContext.WpfExample/Services/IOrderService.cs: -------------------------------------------------------------------------------- 1 | using DapperContext.WpfExample.Model; 2 | 3 | namespace DapperContext.WpfExample.Services 4 | { 5 | public interface IOrderService 6 | { 7 | Order CreateOrder(Customer customer); 8 | OrderLine CreateOrderDetail(Order order, Product product); 9 | OrderLine CreateOrderDetail(Order order, Product product, decimal price, short quantity, float discount); 10 | 11 | void SaveOrder(Order order); 12 | } 13 | } -------------------------------------------------------------------------------- /DapperContext.WpfExample/Services/OrderService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Windows.Documents; 5 | using DapperContext.WpfExample.Model; 6 | using DapperContext.WpfExample.Repository; 7 | using DapperContext.WpfExample.Repository.Sql; 8 | 9 | namespace DapperContext.WpfExample.Services 10 | { 11 | public class OrderService : BaseRepository, IOrderService 12 | { 13 | private readonly ICustomerRepository _customerRepository; 14 | 15 | public OrderService(ICustomerRepository customerRepository) 16 | { 17 | _customerRepository = customerRepository; 18 | } 19 | 20 | private Customer GetDefaultCustomer() 21 | { 22 | return _customerRepository.GetCustomers().First(); 23 | } 24 | 25 | public Order CreateOrder(Customer customer) 26 | { 27 | if (customer == null) 28 | customer = GetDefaultCustomer(); 29 | 30 | return new Order 31 | { 32 | CustomerID = customer.CustomerID, 33 | OrderDate = DateTime.Now, 34 | Lines = new List() 35 | }; 36 | } 37 | 38 | public OrderLine CreateOrderDetail(Order order, Product product) 39 | { 40 | var line = new OrderLine 41 | { 42 | ProductID = product.ProductID, 43 | Quantity = 1, 44 | UnitPrice = product.UnitPrice.GetValueOrDefault(0) 45 | }; 46 | 47 | order.Lines.Add(line); 48 | return line; 49 | } 50 | 51 | public OrderLine CreateOrderDetail(Order order, Product product, decimal price, short quantity, float discount) 52 | { 53 | var line = new OrderLine 54 | { 55 | ProductID = product.ProductID, 56 | Discount = discount, 57 | Quantity = quantity, 58 | UnitPrice = price 59 | }; 60 | 61 | order.Lines.Add(line); 62 | return line; 63 | } 64 | 65 | public void SaveOrder(Order order) 66 | { 67 | using (var context = CreateContext()) 68 | { 69 | using (var scope = context.CreateUnitOfWork()) 70 | { 71 | order.OrderID = context.Query("" + 72 | "INSERT INTO Orders (CustomerID, OrderDate) VALUES (@CustomerID, @OrderDate);" + 73 | "SELECT CAST(SCOPE_IDENTITY() as int)", 74 | new {order.CustomerID, OrderDate = order.OrderDate.Value}).Single(); 75 | 76 | foreach (var line in order.Lines) 77 | { 78 | line.OrderID = order.OrderID; 79 | context.Execute("INSERT INTO [Order Details] (OrderID, ProductID, Discount, UnitPrice, Quantity) VALUES (@OrderID, @ProductID, @Discount, @UnitPrice, @Quantity)", 80 | new { line.OrderID, line.ProductID, line.Discount, line.UnitPrice, line.Quantity }); 81 | } 82 | 83 | scope.SaveChanges(); //And commit this unit of work 84 | } 85 | } 86 | } 87 | } 88 | } -------------------------------------------------------------------------------- /DapperContext.WpfExample/ViewModel/CategoryViewModel.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.ObjectModel; 2 | using DapperContext.WpfExample.Model; 3 | using DapperContext.WpfExample.Repository; 4 | using GalaSoft.MvvmLight; 5 | 6 | namespace DapperContext.WpfExample.ViewModel 7 | { 8 | public class CategoryViewModel : ViewModelBase 9 | { 10 | private readonly ICategoryRepository _repository; 11 | private ObservableCollection _categories; 12 | 13 | public CategoryViewModel(ICategoryRepository repository) 14 | { 15 | _repository = repository; 16 | PopulateCategories(); 17 | } 18 | 19 | public ObservableCollection Categories 20 | { 21 | get { return _categories; } 22 | set { 23 | _categories = value; 24 | RaisePropertyChanged(() => Categories); 25 | } 26 | } 27 | 28 | public void PopulateCategories() 29 | { 30 | if (Categories == null) 31 | Categories = new ObservableCollection(); 32 | else 33 | Categories.Clear(); 34 | 35 | foreach (var category in _repository.GetCategories()) 36 | { 37 | Categories.Add(category); 38 | } 39 | } 40 | } 41 | } -------------------------------------------------------------------------------- /DapperContext.WpfExample/ViewModel/EmployeeViewModel.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.ObjectModel; 2 | using DapperContext.WpfExample.Model; 3 | using DapperContext.WpfExample.Repository; 4 | using GalaSoft.MvvmLight; 5 | 6 | namespace DapperContext.WpfExample.ViewModel 7 | { 8 | public class EmployeeViewModel : ViewModelBase 9 | { 10 | private readonly IEmployeeRepository _repository; 11 | private ObservableCollection _employees; 12 | 13 | public EmployeeViewModel(IEmployeeRepository repository) 14 | { 15 | _repository = repository; 16 | } 17 | 18 | public ObservableCollection Employees 19 | { 20 | get { return _employees; } 21 | set 22 | { 23 | _employees = value; 24 | RaisePropertyChanged(() => Employees); 25 | } 26 | } 27 | 28 | public void PopulateEmployees() 29 | { 30 | if (Employees == null) 31 | Employees = new ObservableCollection(); 32 | else 33 | Employees.Clear(); 34 | 35 | foreach (var employee in _repository.GetEmployees()) 36 | { 37 | Employees.Add(employee); 38 | } 39 | } 40 | } 41 | } -------------------------------------------------------------------------------- /DapperContext.WpfExample/ViewModel/MainViewModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows; 3 | using System.Windows.Input; 4 | using DapperContext.WpfExample.Messages; 5 | using DapperContext.WpfExample.Model; 6 | using DapperContext.WpfExample.Services; 7 | using GalaSoft.MvvmLight; 8 | using GalaSoft.MvvmLight.Command; 9 | 10 | namespace DapperContext.WpfExample.ViewModel 11 | { 12 | /// 13 | /// This class contains properties that the main View can data bind to. 14 | /// 15 | /// Use the mvvminpc snippet to add bindable properties to this ViewModel. 16 | /// 17 | /// 18 | /// You can also use Blend to data bind with the tool's support. 19 | /// 20 | /// 21 | /// See http://www.galasoft.ch/mvvm 22 | /// 23 | /// 24 | public class MainViewModel : ViewModelBase 25 | { 26 | private readonly IOrderService _service; 27 | 28 | private Order _currentOrder; 29 | private Category _selectedCategory; 30 | private Product _selectedProduct; 31 | 32 | /// 33 | /// Initializes a new instance of the MainViewModel class. 34 | /// 35 | public MainViewModel(IOrderService service) 36 | { 37 | _service = service; 38 | AddToOrderCommand = new RelayCommand(AddProductToOrder); 39 | SaveCommand = new RelayCommand(SaveOrder); 40 | } 41 | 42 | public Order CurrentOrder 43 | { 44 | get { return _currentOrder; } 45 | set 46 | { 47 | _currentOrder = value; 48 | RaisePropertyChanged(() => CurrentOrder); 49 | } 50 | } 51 | 52 | public Category SelectedCategory 53 | { 54 | get { return _selectedCategory; } 55 | set 56 | { 57 | if (_selectedCategory == value) 58 | return; 59 | 60 | _selectedCategory = value; 61 | RaisePropertyChanged(() => SelectedCategory); 62 | MessengerInstance.Send(new CategoryChangedMessage(_selectedCategory)); 63 | } 64 | } 65 | 66 | public Product SelectedProduct 67 | { 68 | get { return _selectedProduct; } 69 | set 70 | { 71 | _selectedProduct = value; 72 | RaisePropertyChanged(() => SelectedProduct); 73 | } 74 | } 75 | 76 | public ICommand AddToOrderCommand { get; private set; } 77 | public ICommand SaveCommand { get; private set; } 78 | 79 | private void AddProductToOrder() 80 | { 81 | if (SelectedProduct == null) 82 | return; 83 | 84 | if (CurrentOrder == null) 85 | CurrentOrder = _service.CreateOrder(null); //Let the service use a default customer 86 | 87 | _service.CreateOrderDetail(CurrentOrder, SelectedProduct); 88 | RaisePropertyChanged(() => CurrentOrder); //To indicate that the number of Lines has changed 89 | } 90 | 91 | private void SaveOrder() 92 | { 93 | if (CurrentOrder == null) 94 | return; 95 | 96 | try 97 | { 98 | _service.SaveOrder(CurrentOrder); 99 | MessageBox.Show("Your order has been saved."); 100 | 101 | CurrentOrder = null; //reset 102 | } 103 | catch (Exception e) 104 | { 105 | MessageBox.Show(string.Format("An error occurred while saving your order: {0}", e.Message)); 106 | } 107 | } 108 | } 109 | } -------------------------------------------------------------------------------- /DapperContext.WpfExample/ViewModel/ProductViewModel.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.ObjectModel; 2 | using System.Windows; 3 | using DapperContext.WpfExample.Messages; 4 | using DapperContext.WpfExample.Model; 5 | using DapperContext.WpfExample.Repository; 6 | using GalaSoft.MvvmLight; 7 | 8 | namespace DapperContext.WpfExample.ViewModel 9 | { 10 | public class ProductViewModel : ViewModelBase 11 | { 12 | private readonly IProductRepository _repository; 13 | private ObservableCollection _products; 14 | 15 | 16 | public ProductViewModel(IProductRepository repository) 17 | { 18 | _repository = repository; 19 | MessengerInstance.Register(this, 20 | (CategoryChangedMessage msg) => FindProductsByCategory(msg.Category)); 21 | } 22 | 23 | public ObservableCollection Products 24 | { 25 | get { return _products; } 26 | set 27 | { 28 | _products = value; 29 | RaisePropertyChanged(() => Products); 30 | } 31 | } 32 | 33 | public void PopulateProducts() 34 | { 35 | InitializeCollection(); 36 | foreach (var product in _repository.GetProducts()) 37 | { 38 | Products.Add(product); 39 | } 40 | } 41 | 42 | public void FindProducts(string name) 43 | { 44 | InitializeCollection(); 45 | if (string.IsNullOrEmpty(name)) 46 | return; 47 | 48 | foreach (var product in _repository.GetProducts(name)) 49 | { 50 | Products.Add(product); 51 | } 52 | } 53 | 54 | public void FindProductsByCategory(Category category) 55 | { 56 | InitializeCollection(); 57 | if (category == null) 58 | return; 59 | 60 | foreach (var product in _repository.GetProductsByCategory(category)) 61 | { 62 | Products.Add(product); 63 | } 64 | } 65 | 66 | private void InitializeCollection() 67 | { 68 | if (Products == null) 69 | Products = new ObservableCollection(); 70 | else 71 | Products.Clear(); 72 | } 73 | } 74 | } -------------------------------------------------------------------------------- /DapperContext.WpfExample/ViewModel/ViewModelLocator.cs: -------------------------------------------------------------------------------- 1 | /* 2 | In App.xaml: 3 | 4 | 6 | 7 | 8 | In the View: 9 | DataContext="{Binding Source={StaticResource Locator}, Path=ViewModelName}" 10 | 11 | You can also use Blend to do all this with the tool's support. 12 | See http://www.galasoft.ch/mvvm 13 | */ 14 | 15 | using Dapper; 16 | using DapperContext.WpfExample.Repository; 17 | using DapperContext.WpfExample.Repository.Sql; 18 | using DapperContext.WpfExample.Services; 19 | using GalaSoft.MvvmLight; 20 | using GalaSoft.MvvmLight.Ioc; 21 | using Microsoft.Practices.ServiceLocation; 22 | 23 | namespace DapperContext.WpfExample.ViewModel 24 | { 25 | /// 26 | /// This class contains static references to all the view models in the 27 | /// application and provides an entry point for the bindings. 28 | /// 29 | public class ViewModelLocator 30 | { 31 | /// 32 | /// Initializes a new instance of the ViewModelLocator class. 33 | /// 34 | public ViewModelLocator() 35 | { 36 | ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default); 37 | 38 | //Repositories 39 | SimpleIoc.Default.Register(); 40 | SimpleIoc.Default.Register(); 41 | SimpleIoc.Default.Register(); 42 | SimpleIoc.Default.Register(); 43 | SimpleIoc.Default.Register(); 44 | 45 | SimpleIoc.Default.Register(); 46 | 47 | //Viewmodels 48 | SimpleIoc.Default.Register(); 49 | SimpleIoc.Default.Register(); 50 | SimpleIoc.Default.Register(); 51 | SimpleIoc.Default.Register(); 52 | 53 | } 54 | 55 | public MainViewModel Main 56 | { 57 | get 58 | { 59 | return ServiceLocator.Current.GetInstance(); 60 | } 61 | } 62 | 63 | public CategoryViewModel Category 64 | { 65 | get 66 | { 67 | return ServiceLocator.Current.GetInstance(); 68 | } 69 | } 70 | 71 | public EmployeeViewModel Employee 72 | { 73 | get 74 | { 75 | return ServiceLocator.Current.GetInstance(); 76 | } 77 | } 78 | 79 | public ProductViewModel Product 80 | { 81 | get 82 | { 83 | return ServiceLocator.Current.GetInstance(); 84 | } 85 | } 86 | 87 | 88 | public static void Cleanup() 89 | { 90 | // TODO Clear the ViewModels 91 | } 92 | } 93 | } -------------------------------------------------------------------------------- /DapperContext.WpfExample/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /DapperContext.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | DapperContext 5 | 0.1.2-alpha 6 | Wesley Cabus 7 | Wesley Cabus 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | http://wcabus.github.io/DapperContext 10 | false 11 | DapperContext is a DbContext-like implementation for Dapper, supporting the Unit Of Work pattern and simplifying usage with repository classes and IOC containers. 12 | dapper orm dbcontext sql unit-of-work repository 13 | 14 | 15 | 16 | 17 | * 0.1.2 - Referenced a wrong version of the Dapper dependency. Fixed. 18 | * 0.1.1 - First alpha release. 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /DapperContext.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.21005.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DapperContext.NET35", "DapperContext.NET35\DapperContext.NET35.csproj", "{CBAD325F-3F61-495A-BC28-177FF9CF0A13}" 7 | EndProject 8 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{73CE9CAB-EA50-447C-8B98-EB543C303DD9}" 9 | ProjectSection(SolutionItems) = preProject 10 | .nuget\NuGet.Config = .nuget\NuGet.Config 11 | .nuget\NuGet.exe = .nuget\NuGet.exe 12 | .nuget\NuGet.targets = .nuget\NuGet.targets 13 | EndProjectSection 14 | EndProject 15 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DapperContext.NET40", "DapperContext.NET40\DapperContext.NET40.csproj", "{2224F63F-3D00-4E24-A38A-86DE147E1A5A}" 16 | EndProject 17 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DapperContext.WpfExample", "DapperContext.WpfExample\DapperContext.WpfExample.csproj", "{B85ED38C-5EAE-4EDF-A2A2-CFA7FD40B519}" 18 | EndProject 19 | Global 20 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 21 | Debug|Any CPU = Debug|Any CPU 22 | Release|Any CPU = Release|Any CPU 23 | EndGlobalSection 24 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 25 | {CBAD325F-3F61-495A-BC28-177FF9CF0A13}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 26 | {CBAD325F-3F61-495A-BC28-177FF9CF0A13}.Debug|Any CPU.Build.0 = Debug|Any CPU 27 | {CBAD325F-3F61-495A-BC28-177FF9CF0A13}.Release|Any CPU.ActiveCfg = Release|Any CPU 28 | {CBAD325F-3F61-495A-BC28-177FF9CF0A13}.Release|Any CPU.Build.0 = Release|Any CPU 29 | {2224F63F-3D00-4E24-A38A-86DE147E1A5A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 30 | {2224F63F-3D00-4E24-A38A-86DE147E1A5A}.Debug|Any CPU.Build.0 = Debug|Any CPU 31 | {2224F63F-3D00-4E24-A38A-86DE147E1A5A}.Release|Any CPU.ActiveCfg = Release|Any CPU 32 | {2224F63F-3D00-4E24-A38A-86DE147E1A5A}.Release|Any CPU.Build.0 = Release|Any CPU 33 | {B85ED38C-5EAE-4EDF-A2A2-CFA7FD40B519}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 34 | {B85ED38C-5EAE-4EDF-A2A2-CFA7FD40B519}.Debug|Any CPU.Build.0 = Debug|Any CPU 35 | {B85ED38C-5EAE-4EDF-A2A2-CFA7FD40B519}.Release|Any CPU.ActiveCfg = Release|Any CPU 36 | EndGlobalSection 37 | GlobalSection(SolutionProperties) = preSolution 38 | HideSolutionNode = FALSE 39 | EndGlobalSection 40 | EndGlobal 41 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | 203 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | DapperContext 2 | ============= 3 | 4 | A DbContext like implementation for Dapper, supporting the Unit Of Work pattern and simplifying usage with repository classes and IOC containers. 5 | --------------------------------------------------------------------------------