Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class AdoNetUnitOfWork : IUnitOfWork
- {
- public AdoNetUnitOfWork(IDbConnection connection, bool ownsConnection)
- {
- _connection = connection;
- _ownsConnection=ownsConnection;
- _transaction = connection.BeginTransaction();
- }
- public IDbCommand CreateCommand()
- {
- var command = _connection.CreateCommand();
- command.Transaction = _transaction;
- return command;
- }
- public void SaveChanges()
- {
- if (_transaction == null)
- throw new InvalidOperationException("Transaction have already been commited. Check your transaction handling.");
- _transaction.Commit();
- _transaction = null;
- }
- public void Dispose()
- {
- if (_transaction != null)
- {
- _transaction.Rollback();
- _transaction = null;
- }
- if (_connection != null && _ownsConnection)
- {
- _connection.Close();
- _connection = null;
- }
- }
- }
- public DomainTable Get(int id)
- {
- DomainTable table;
- using (var commandTable = _unitOfWork.CreateCommand())
- {
- commandTable.CommandType = CommandType.StoredProcedure;
- //This stored procedure contains just a simple SELECT statement
- commandTable.CommandText = "up_DomainTable_GetById";
- commandTable.Parameters.Add(commandTable.CreateParameter("@pId", id));
- table = ToList(commandTable).FirstOrDefault();
- }
- return table;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement