Esempio n. 1
0
 /// <summary>
 /// Executes the non query.
 /// </summary>
 /// <param name="transactionManager">The transaction manager.</param>
 /// <param name="commandWrapper">The command wrapper.</param>
 public override void ExecuteNonQuery(TransactionManager transactionManager, DbCommand commandWrapper)
 {
     SqlDatabase database = new SqlDatabase(this._connectionString);
     database.ExecuteNonQuery(commandWrapper, transactionManager.TransactionObject);
 }
        /// <summary>
        /// 	Inserts a Library.BLL.Employee object into the datasource using a transaction.
        /// </summary>
        /// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
        /// <param name="entity">Library.BLL.Employee object to insert.</param>
        /// <remarks>
        ///		After inserting into the datasource, the Library.BLL.Employee object will be updated
        /// 	to refelect any changes made by the datasource. (ie: identity or computed columns)
        /// </remarks>	
        /// <returns>Returns true if operation is successful.</returns>
        /// <exception cref="System.Exception">The command could not be executed.</exception>
        /// <exception cref="System.Data.DataException">The <paramref name="transactionManager"/> is not open.</exception>
        /// <exception cref="System.Data.Common.DbException">The command could not be executed.</exception>
        public override bool Insert(TransactionManager transactionManager, Library.BLL.Employee entity)
        {
            SqlDatabase database = new SqlDatabase(this._connectionString);
            DbCommand commandWrapper = StoredProcedureProvider.GetCommandWrapper(database, "dbo.Employee_Insert", _useStoredProcedure);

            database.AddOutParameter(commandWrapper, "@ID", DbType.Int32, 4);
            database.AddInParameter(commandWrapper, "@UserName", DbType.String, entity.UserName );
            database.AddInParameter(commandWrapper, "@Password", DbType.String, entity.Password );
            database.AddInParameter(commandWrapper, "@Last_Login", DbType.DateTime, (entity.Last_Login.HasValue ? (object) entity.Last_Login  : System.DBNull.Value));
            database.AddInParameter(commandWrapper, "@Last_Logout", DbType.DateTime, entity.Last_Logout );
            database.AddInParameter(commandWrapper, "@Is_Online", DbType.Boolean, (entity.Is_Online.HasValue ? (object) entity.Is_Online  : System.DBNull.Value));
            database.AddInParameter(commandWrapper, "@Is_Active", DbType.Boolean, (entity.Is_Active.HasValue ? (object) entity.Is_Active  : System.DBNull.Value));
            database.AddInParameter(commandWrapper, "@Is_Admin", DbType.Boolean, (entity.Is_Admin.HasValue ? (object) entity.Is_Admin  : System.DBNull.Value));
            database.AddInParameter(commandWrapper, "@First_Name", DbType.String, entity.First_Name );
            database.AddInParameter(commandWrapper, "@Last_Name", DbType.String, entity.Last_Name );
            database.AddInParameter(commandWrapper, "@Email", DbType.String, entity.Email );
            database.AddInParameter(commandWrapper, "@Country", DbType.String, entity.Country );
            database.AddInParameter(commandWrapper, "@City", DbType.String, entity.City );
            database.AddInParameter(commandWrapper, "@Address", DbType.String, entity.Address );
            database.AddInParameter(commandWrapper, "@Mobile", DbType.String, entity.Mobile );
            database.AddInParameter(commandWrapper, "@Phone", DbType.String, entity.Phone );
            database.AddInParameter(commandWrapper, "@Postion", DbType.String, entity.Postion );
            database.AddInParameter(commandWrapper, "@Is_Deleted", DbType.Boolean, (entity.Is_Deleted.HasValue ? (object) entity.Is_Deleted  : System.DBNull.Value));
            database.AddInParameter(commandWrapper, "@CreatedOn", DbType.DateTime, (entity.CreatedOn.HasValue ? (object) entity.CreatedOn  : System.DBNull.Value));
            database.AddInParameter(commandWrapper, "@CreatedBy", DbType.Int32, (entity.CreatedBy.HasValue ? (object) entity.CreatedBy  : System.DBNull.Value));
            database.AddInParameter(commandWrapper, "@UpdatedOn", DbType.DateTime, (entity.UpdatedOn.HasValue ? (object) entity.UpdatedOn  : System.DBNull.Value));
            database.AddInParameter(commandWrapper, "@UpdatedBy", DbType.Int32, (entity.UpdatedBy.HasValue ? (object) entity.UpdatedBy  : System.DBNull.Value));
            database.AddInParameter(commandWrapper, "@DeletedOn", DbType.DateTime, (entity.DeletedOn.HasValue ? (object) entity.DeletedOn  : System.DBNull.Value));
            database.AddInParameter(commandWrapper, "@DeletedBy", DbType.Int32, (entity.DeletedBy.HasValue ? (object) entity.DeletedBy  : System.DBNull.Value));

            int results = 0;

            //Provider Data Requesting Command Event
            OnDataRequesting(new CommandEventArgs(commandWrapper, "Insert", entity));

            if (transactionManager != null)
            {
                results = Utility.ExecuteNonQuery(transactionManager, commandWrapper);
            }
            else
            {
                results = Utility.ExecuteNonQuery(database,commandWrapper);
            }

            object _iD = database.GetParameterValue(commandWrapper, "@ID");
            entity.ID = (System.Int32)_iD;

            entity.AcceptChanges();

            //Provider Data Requested Command Event
            OnDataRequested(new CommandEventArgs(commandWrapper, "Insert", entity));

            return Convert.ToBoolean(results);
        }
        /// <summary>
        /// 	Gets rows from the datasource based on the PK_Image index.
        /// </summary>
        /// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
        /// <param name="_iD"></param>
        /// <param name="start">Row number at which to start reading.</param>
        /// <param name="pageLength">Number of rows to return.</param>
        /// <param name="count">out parameter to get total records for query.</param>
        /// <returns>Returns an instance of the <see cref="Library.BLL.BookImage"/> class.</returns>
        /// <remarks></remarks>
        /// <exception cref="System.Exception">The command could not be executed.</exception>
        /// <exception cref="System.Data.DataException">The <paramref name="transactionManager"/> is not open.</exception>
        /// <exception cref="System.Data.Common.DbException">The command could not be executed.</exception>
        public override Library.BLL.BookImage GetByID(TransactionManager transactionManager, System.Int32 _iD, int start, int pageLength, out int count)
        {
            SqlDatabase database = new SqlDatabase(this._connectionString);
            DbCommand commandWrapper = StoredProcedureProvider.GetCommandWrapper(database, "dbo.BookImage_GetByID", _useStoredProcedure);

                database.AddInParameter(commandWrapper, "@ID", DbType.Int32, _iD);

            IDataReader reader = null;
            TList<BookImage> tmp = new TList<BookImage>();
            try
            {
                //Provider Data Requesting Command Event
                OnDataRequesting(new CommandEventArgs(commandWrapper, "GetByID", tmp));

                if (transactionManager != null)
                {
                    reader = Utility.ExecuteReader(transactionManager, commandWrapper);
                }
                else
                {
                    reader = Utility.ExecuteReader(database, commandWrapper);
                }

                //Create collection and fill
                Fill(reader, tmp, start, pageLength);
                count = -1;
                if(reader.NextResult())
                {
                    if(reader.Read())
                    {
                        count = reader.GetInt32(0);
                    }
                }

                //Provider Data Requested Command Event
                OnDataRequested(new CommandEventArgs(commandWrapper, "GetByID", tmp));
            }
            finally
            {
                if (reader != null)
                    reader.Close();

                commandWrapper = null;
            }

            if (tmp.Count == 1)
            {
                return tmp[0];
            }
            else if (tmp.Count == 0)
            {
                return null;
            }
            else
            {
                throw new DataException("Cannot find the unique instance of the class.");
            }

            //return rows;
        }
        /// <summary>
        /// 	Inserts a Library.BLL.BookImage object into the datasource using a transaction.
        /// </summary>
        /// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
        /// <param name="entity">Library.BLL.BookImage object to insert.</param>
        /// <remarks>
        ///		After inserting into the datasource, the Library.BLL.BookImage object will be updated
        /// 	to refelect any changes made by the datasource. (ie: identity or computed columns)
        /// </remarks>	
        /// <returns>Returns true if operation is successful.</returns>
        /// <exception cref="System.Exception">The command could not be executed.</exception>
        /// <exception cref="System.Data.DataException">The <paramref name="transactionManager"/> is not open.</exception>
        /// <exception cref="System.Data.Common.DbException">The command could not be executed.</exception>
        public override bool Insert(TransactionManager transactionManager, Library.BLL.BookImage entity)
        {
            SqlDatabase database = new SqlDatabase(this._connectionString);
            DbCommand commandWrapper = StoredProcedureProvider.GetCommandWrapper(database, "dbo.BookImage_Insert", _useStoredProcedure);

            database.AddOutParameter(commandWrapper, "@ID", DbType.Int32, 4);
            database.AddInParameter(commandWrapper, "@Name", DbType.String, entity.Name );
            database.AddInParameter(commandWrapper, "@Format", DbType.String, entity.Format );
            database.AddInParameter(commandWrapper, "@Size", DbType.String, entity.Size );
            database.AddInParameter(commandWrapper, "@Link", DbType.String, entity.Link );
            database.AddInParameter(commandWrapper, "@IsAvailable", DbType.String, entity.IsAvailable );

            int results = 0;

            //Provider Data Requesting Command Event
            OnDataRequesting(new CommandEventArgs(commandWrapper, "Insert", entity));

            if (transactionManager != null)
            {
                results = Utility.ExecuteNonQuery(transactionManager, commandWrapper);
            }
            else
            {
                results = Utility.ExecuteNonQuery(database,commandWrapper);
            }

            object _iD = database.GetParameterValue(commandWrapper, "@ID");
            entity.ID = (System.Int32)_iD;

            entity.AcceptChanges();

            //Provider Data Requested Command Event
            OnDataRequested(new CommandEventArgs(commandWrapper, "Insert", entity));

            return Convert.ToBoolean(results);
        }
        /// <summary>
        /// 	Deletes a row from the DataSource.
        /// </summary>
        /// <param name="_iD">. Primary Key.</param>	
        /// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
        /// <remarks>Deletes based on primary key(s).</remarks>
        /// <returns>Returns true if operation suceeded.</returns>
        /// <exception cref="System.Exception">The command could not be executed.</exception>
        /// <exception cref="System.Data.DataException">The <paramref name="transactionManager"/> is not open.</exception>
        /// <exception cref="System.Data.Common.DbException">The command could not be executed.</exception>
        public override bool Delete(TransactionManager transactionManager, System.Int32 _iD)
        {
            SqlDatabase database = new SqlDatabase(this._connectionString);
            DbCommand commandWrapper = StoredProcedureProvider.GetCommandWrapper(database, "dbo.BookImage_Delete", _useStoredProcedure);
            database.AddInParameter(commandWrapper, "@ID", DbType.Int32, _iD);

            //Provider Data Requesting Command Event
            OnDataRequesting(new CommandEventArgs(commandWrapper, "Delete"));

            int results = 0;

            if (transactionManager != null)
            {
                results = Utility.ExecuteNonQuery(transactionManager, commandWrapper);
            }
            else
            {
                results = Utility.ExecuteNonQuery(database,commandWrapper);
            }

            //Stop Tracking Now that it has been updated and persisted.
            if (DataRepository.Provider.EnableEntityTracking)
            {
                string entityKey = EntityLocator.ConstructKeyFromPkItems(typeof(BookImage)
                    ,_iD);
                EntityManager.StopTracking(entityKey);

            }

            //Provider Data Requested Command Event
            OnDataRequested(new CommandEventArgs(commandWrapper, "Delete"));

            commandWrapper = null;

            return Convert.ToBoolean(results);
        }
        /// <summary>
        /// 	Returns rows from the DataSource that meet the parameter conditions.
        /// </summary>
        /// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
        /// <param name="parameters">A collection of <see cref="SqlFilterParameter"/> objects.</param>
        /// <param name="orderBy">Specifies the sort criteria for the rows in the DataSource (Name ASC; BirthDay DESC, Name ASC);</param>
        /// <param name="start">Row number at which to start reading.</param>
        /// <param name="pageLength">Number of rows to return.</param>
        /// <param name="count">out. The number of rows that match this query.</param>
        /// <returns>Returns a typed collection of Library.BLL.BookImage objects.</returns>
        public override TList<BookImage> Find(TransactionManager transactionManager, IFilterParameterCollection parameters, string orderBy, int start, int pageLength, out int count)
        {
            SqlFilterParameterCollection filter = null;

            if (parameters == null)
                filter = new SqlFilterParameterCollection();
            else
                filter = parameters.GetParameters();

            SqlDatabase database = new SqlDatabase(this._connectionString);
            DbCommand commandWrapper = StoredProcedureProvider.GetCommandWrapper(database, "dbo.BookImage_Find_Dynamic", typeof(BookImageColumn), filter, orderBy, start, pageLength);

            SqlFilterParameter param;

            for ( int i = 0; i < filter.Count; i++ )
            {
                param = filter[i];
                database.AddInParameter(commandWrapper, param.Name, param.DbType, param.GetValue());
            }

            TList<BookImage> rows = new TList<BookImage>();
            IDataReader reader = null;

            try
            {
                //Provider Data Requesting Command Event
                OnDataRequesting(new CommandEventArgs(commandWrapper, "Find", rows));

                if ( transactionManager != null )
                {
                    reader = Utility.ExecuteReader(transactionManager, commandWrapper);
                }
                else
                {
                    reader = Utility.ExecuteReader(database, commandWrapper);
                }

                Fill(reader, rows, 0, int.MaxValue);
                count = rows.Count;

                if ( reader.NextResult() )
                {
                    if ( reader.Read() )
                    {
                        count = reader.GetInt32(0);
                    }
                }

                //Provider Data Requested Command Event
                OnDataRequested(new CommandEventArgs(commandWrapper, "Find", rows));
            }
            finally
            {
                if ( reader != null )
                    reader.Close();

                commandWrapper = null;
            }

            return rows;
        }
        /// <summary>
        /// 	Inserts a Library.BLL.Course object into the datasource using a transaction.
        /// </summary>
        /// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
        /// <param name="entity">Library.BLL.Course object to insert.</param>
        /// <remarks>
        ///		After inserting into the datasource, the Library.BLL.Course object will be updated
        /// 	to refelect any changes made by the datasource. (ie: identity or computed columns)
        /// </remarks>	
        /// <returns>Returns true if operation is successful.</returns>
        /// <exception cref="System.Exception">The command could not be executed.</exception>
        /// <exception cref="System.Data.DataException">The <paramref name="transactionManager"/> is not open.</exception>
        /// <exception cref="System.Data.Common.DbException">The command could not be executed.</exception>
        public override bool Insert(TransactionManager transactionManager, Library.BLL.Course entity)
        {
            SqlDatabase database = new SqlDatabase(this._connectionString);
            DbCommand commandWrapper = StoredProcedureProvider.GetCommandWrapper(database, "dbo.Course_Insert", _useStoredProcedure);

            database.AddOutParameter(commandWrapper, "@ID", DbType.Int32, 4);
            database.AddInParameter(commandWrapper, "@Course_Name", DbType.String, entity.Course_Name );
            database.AddInParameter(commandWrapper, "@Course_Scope", DbType.Int32, entity.Course_Scope );
            database.AddInParameter(commandWrapper, "@Duration", DbType.Int32, entity.Duration );
            database.AddInParameter(commandWrapper, "@DurationType_ID", DbType.Int32, entity.DurationType_ID );
            database.AddInParameter(commandWrapper, "@Is_Deleted", DbType.Boolean, (entity.Is_Deleted.HasValue ? (object) entity.Is_Deleted  : System.DBNull.Value));
            database.AddInParameter(commandWrapper, "@CreatedOn", DbType.DateTime, (entity.CreatedOn.HasValue ? (object) entity.CreatedOn  : System.DBNull.Value));
            database.AddInParameter(commandWrapper, "@CreatedBy", DbType.Int32, (entity.CreatedBy.HasValue ? (object) entity.CreatedBy  : System.DBNull.Value));
            database.AddInParameter(commandWrapper, "@UpdatedOn", DbType.DateTime, (entity.UpdatedOn.HasValue ? (object) entity.UpdatedOn  : System.DBNull.Value));
            database.AddInParameter(commandWrapper, "@UpdatedBy", DbType.Int32, (entity.UpdatedBy.HasValue ? (object) entity.UpdatedBy  : System.DBNull.Value));
            database.AddInParameter(commandWrapper, "@DeletedOn", DbType.DateTime, (entity.DeletedOn.HasValue ? (object) entity.DeletedOn  : System.DBNull.Value));
            database.AddInParameter(commandWrapper, "@DeletedBy", DbType.Int32, (entity.DeletedBy.HasValue ? (object) entity.DeletedBy  : System.DBNull.Value));

            int results = 0;

            //Provider Data Requesting Command Event
            OnDataRequesting(new CommandEventArgs(commandWrapper, "Insert", entity));

            if (transactionManager != null)
            {
                results = Utility.ExecuteNonQuery(transactionManager, commandWrapper);
            }
            else
            {
                results = Utility.ExecuteNonQuery(database,commandWrapper);
            }

            object _iD = database.GetParameterValue(commandWrapper, "@ID");
            entity.ID = (System.Int32)_iD;

            entity.AcceptChanges();

            //Provider Data Requested Command Event
            OnDataRequested(new CommandEventArgs(commandWrapper, "Insert", entity));

            return Convert.ToBoolean(results);
        }
        /// <summary>
        /// 	Gets rows from the datasource based on the FK_Book_Author_Book key.
        ///		FK_Book_Author_Book Description: 
        /// </summary>
        /// <param name="start">Row number at which to start reading.</param>
        /// <param name="pageLength">Number of rows to return.</param>
        /// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
        /// <param name="_book_ID"></param>
        /// <param name="count">out parameter to get total records for query</param>
        /// <remarks></remarks>
        /// <returns>Returns a typed collection of Library.BLL.Book_Author objects.</returns>
        /// <exception cref="System.Exception">The command could not be executed.</exception>
        /// <exception cref="System.Data.DataException">The <paramref name="transactionManager"/> is not open.</exception>
        /// <exception cref="System.Data.Common.DbException">The command could not be executed.</exception>
        public override TList<Book_Author> GetByBook_ID(TransactionManager transactionManager, System.Int32 _book_ID, int start, int pageLength, out int count)
        {
            SqlDatabase database = new SqlDatabase(this._connectionString);
            DbCommand commandWrapper = StoredProcedureProvider.GetCommandWrapper(database, "dbo.Book_Author_GetByBook_ID", _useStoredProcedure);

                database.AddInParameter(commandWrapper, "@Book_ID", DbType.Int32, _book_ID);

            IDataReader reader = null;
            TList<Book_Author> rows = new TList<Book_Author>();
            try
            {
                //Provider Data Requesting Command Event
                OnDataRequesting(new CommandEventArgs(commandWrapper, "GetByBook_ID", rows));

                if (transactionManager != null)
                {
                    reader = Utility.ExecuteReader(transactionManager, commandWrapper);
                }
                else
                {
                    reader = Utility.ExecuteReader(database, commandWrapper);
                }

                //Create Collection
                Fill(reader, rows, start, pageLength);
                count = -1;
                if(reader.NextResult())
                {
                    if(reader.Read())
                    {
                        count = reader.GetInt32(0);
                    }
                }

                //Provider Data Requested Command Event
                OnDataRequested(new CommandEventArgs(commandWrapper, "GetByBook_ID", rows));
            }
            finally
            {
                if (reader != null)
                    reader.Close();

                commandWrapper = null;
            }
            return rows;
        }
Esempio n. 9
0
 /// <summary>
 /// Executes the scalar.
 /// </summary>
 /// <param name="transactionManager">The transaction manager.</param>
 /// <param name="commandType">Type of the command.</param>
 /// <param name="commandText">The command text.</param>
 /// <returns></returns>
 public override object ExecuteScalar(TransactionManager transactionManager, CommandType commandType, string commandText)
 {
     Database database = transactionManager.Database;
     return database.ExecuteScalar(transactionManager.TransactionObject , commandType, commandText);
 }
        /// <summary>
        /// Lets you efficiently bulk insert many entities to the database.
        /// </summary>
        /// <param name="transactionManager">The transaction manager.</param>
        /// <param name="entities">The entities.</param>
        /// <remarks>
        ///		After inserting into the datasource, the Library.BLL.Course object will be updated
        /// 	to refelect any changes made by the datasource. (ie: identity or computed columns)
        /// </remarks>	
        public override void BulkInsert(TransactionManager transactionManager, TList<Library.BLL.Course> entities)
        {
            //System.Data.SqlClient.SqlBulkCopy bulkCopy = new System.Data.SqlClient.SqlBulkCopy(this._connectionString, System.Data.SqlClient.SqlBulkCopyOptions.CheckConstraints); //, null);

            System.Data.SqlClient.SqlBulkCopy bulkCopy = null;

            if (transactionManager != null && transactionManager.IsOpen)
            {
                System.Data.SqlClient.SqlConnection cnx = transactionManager.TransactionObject.Connection as System.Data.SqlClient.SqlConnection;
                System.Data.SqlClient.SqlTransaction transaction = transactionManager.TransactionObject as System.Data.SqlClient.SqlTransaction;
                bulkCopy = new System.Data.SqlClient.SqlBulkCopy(cnx, System.Data.SqlClient.SqlBulkCopyOptions.CheckConstraints, transaction); //, null);
            }
            else
            {
                bulkCopy = new System.Data.SqlClient.SqlBulkCopy(this._connectionString, System.Data.SqlClient.SqlBulkCopyOptions.CheckConstraints); //, null);
            }

            bulkCopy.BulkCopyTimeout = 360;
            bulkCopy.DestinationTableName = "Course";

            DataTable dataTable = new DataTable();
            DataColumn col0 = dataTable.Columns.Add("ID", typeof(System.Int32));
            col0.AllowDBNull = false;
            DataColumn col1 = dataTable.Columns.Add("Course_Name", typeof(System.String));
            col1.AllowDBNull = false;
            DataColumn col2 = dataTable.Columns.Add("Course_Scope", typeof(System.Int32));
            col2.AllowDBNull = false;
            DataColumn col3 = dataTable.Columns.Add("Duration", typeof(System.Int32));
            col3.AllowDBNull = false;
            DataColumn col4 = dataTable.Columns.Add("DurationType_ID", typeof(System.Int32));
            col4.AllowDBNull = false;
            DataColumn col5 = dataTable.Columns.Add("Is_Deleted", typeof(System.Boolean));
            col5.AllowDBNull = true;
            DataColumn col6 = dataTable.Columns.Add("CreatedOn", typeof(System.DateTime));
            col6.AllowDBNull = true;
            DataColumn col7 = dataTable.Columns.Add("CreatedBy", typeof(System.Int32));
            col7.AllowDBNull = true;
            DataColumn col8 = dataTable.Columns.Add("UpdatedOn", typeof(System.DateTime));
            col8.AllowDBNull = true;
            DataColumn col9 = dataTable.Columns.Add("UpdatedBy", typeof(System.Int32));
            col9.AllowDBNull = true;
            DataColumn col10 = dataTable.Columns.Add("DeletedOn", typeof(System.DateTime));
            col10.AllowDBNull = true;
            DataColumn col11 = dataTable.Columns.Add("DeletedBy", typeof(System.Int32));
            col11.AllowDBNull = true;

            bulkCopy.ColumnMappings.Add("ID", "ID");
            bulkCopy.ColumnMappings.Add("Course_Name", "Course_Name");
            bulkCopy.ColumnMappings.Add("Course_Scope", "Course_Scope");
            bulkCopy.ColumnMappings.Add("Duration", "Duration");
            bulkCopy.ColumnMappings.Add("DurationType_ID", "DurationType_ID");
            bulkCopy.ColumnMappings.Add("Is_Deleted", "Is_Deleted");
            bulkCopy.ColumnMappings.Add("CreatedOn", "CreatedOn");
            bulkCopy.ColumnMappings.Add("CreatedBy", "CreatedBy");
            bulkCopy.ColumnMappings.Add("UpdatedOn", "UpdatedOn");
            bulkCopy.ColumnMappings.Add("UpdatedBy", "UpdatedBy");
            bulkCopy.ColumnMappings.Add("DeletedOn", "DeletedOn");
            bulkCopy.ColumnMappings.Add("DeletedBy", "DeletedBy");

            foreach(Library.BLL.Course entity in entities)
            {
                if (entity.EntityState != EntityState.Added)
                    continue;

                DataRow row = dataTable.NewRow();

                    row["ID"] = entity.ID;

                    row["Course_Name"] = entity.Course_Name;

                    row["Course_Scope"] = entity.Course_Scope;

                    row["Duration"] = entity.Duration;

                    row["DurationType_ID"] = entity.DurationType_ID;

                    row["Is_Deleted"] = entity.Is_Deleted.HasValue ? (object) entity.Is_Deleted  : System.DBNull.Value;

                    row["CreatedOn"] = entity.CreatedOn.HasValue ? (object) entity.CreatedOn  : System.DBNull.Value;

                    row["CreatedBy"] = entity.CreatedBy.HasValue ? (object) entity.CreatedBy  : System.DBNull.Value;

                    row["UpdatedOn"] = entity.UpdatedOn.HasValue ? (object) entity.UpdatedOn  : System.DBNull.Value;

                    row["UpdatedBy"] = entity.UpdatedBy.HasValue ? (object) entity.UpdatedBy  : System.DBNull.Value;

                    row["DeletedOn"] = entity.DeletedOn.HasValue ? (object) entity.DeletedOn  : System.DBNull.Value;

                    row["DeletedBy"] = entity.DeletedBy.HasValue ? (object) entity.DeletedBy  : System.DBNull.Value;

                dataTable.Rows.Add(row);
            }

            // send the data to the server
            bulkCopy.WriteToServer(dataTable);

            // update back the state
            foreach(Library.BLL.Course entity in entities)
            {
                if (entity.EntityState != EntityState.Added)
                    continue;

                entity.AcceptChanges();
            }
        }
Esempio n. 11
0
 /// <summary>
 /// Executes the scalar.
 /// </summary>
 /// <param name="transactionManager">The transaction manager.</param>
 /// <param name="commandWrapper">The command wrapper.</param>
 /// <returns></returns>
 public override object ExecuteScalar(TransactionManager transactionManager, DbCommand commandWrapper)
 {
     Database database = transactionManager.Database;
     return database.ExecuteScalar(commandWrapper, transactionManager.TransactionObject);
 }
Esempio n. 12
0
 /// <summary>
 /// Executes the scalar.
 /// </summary>
 /// <param name="transactionManager">The transaction manager.</param>
 /// <param name="storedProcedureName">Name of the stored procedure.</param>
 /// <param name="parameterValues">The parameter values.</param>
 /// <returns></returns>
 public override object ExecuteScalar(TransactionManager transactionManager, string storedProcedureName, params object[] parameterValues)
 {
     Database database = transactionManager.Database;
     return database.ExecuteScalar(transactionManager.TransactionObject, storedProcedureName, parameterValues);
 }
Esempio n. 13
0
 /// <summary>
 /// Executes the non query.
 /// </summary>
 /// <param name="transactionManager">The transaction manager.</param>
 /// <param name="commandType">Type of the command.</param>
 /// <param name="commandText">The command text.</param>
 /// <returns></returns>
 public override int ExecuteNonQuery(TransactionManager transactionManager, CommandType commandType, string commandText)
 {
     Database database = transactionManager.Database;
     return database.ExecuteNonQuery(transactionManager.TransactionObject , commandType, commandText);
 }
        /// <summary>
        /// Lets you efficiently bulk insert many entities to the database.
        /// </summary>
        /// <param name="transactionManager">The transaction manager.</param>
        /// <param name="entities">The entities.</param>
        /// <remarks>
        ///		After inserting into the datasource, the Library.BLL.Book object will be updated
        /// 	to refelect any changes made by the datasource. (ie: identity or computed columns)
        /// </remarks>	
        public override void BulkInsert(TransactionManager transactionManager, TList<Library.BLL.Book> entities)
        {
            //System.Data.SqlClient.SqlBulkCopy bulkCopy = new System.Data.SqlClient.SqlBulkCopy(this._connectionString, System.Data.SqlClient.SqlBulkCopyOptions.CheckConstraints); //, null);

            System.Data.SqlClient.SqlBulkCopy bulkCopy = null;

            if (transactionManager != null && transactionManager.IsOpen)
            {
                System.Data.SqlClient.SqlConnection cnx = transactionManager.TransactionObject.Connection as System.Data.SqlClient.SqlConnection;
                System.Data.SqlClient.SqlTransaction transaction = transactionManager.TransactionObject as System.Data.SqlClient.SqlTransaction;
                bulkCopy = new System.Data.SqlClient.SqlBulkCopy(cnx, System.Data.SqlClient.SqlBulkCopyOptions.CheckConstraints, transaction); //, null);
            }
            else
            {
                bulkCopy = new System.Data.SqlClient.SqlBulkCopy(this._connectionString, System.Data.SqlClient.SqlBulkCopyOptions.CheckConstraints); //, null);
            }

            bulkCopy.BulkCopyTimeout = 360;
            bulkCopy.DestinationTableName = "Book";

            DataTable dataTable = new DataTable();
            DataColumn col0 = dataTable.Columns.Add("ID", typeof(System.Int32));
            col0.AllowDBNull = false;
            DataColumn col1 = dataTable.Columns.Add("Name", typeof(System.String));
            col1.AllowDBNull = false;
            DataColumn col2 = dataTable.Columns.Add("Publisher", typeof(System.String));
            col2.AllowDBNull = false;
            DataColumn col3 = dataTable.Columns.Add("Publish_Date", typeof(System.DateTime));
            col3.AllowDBNull = true;
            DataColumn col4 = dataTable.Columns.Add("IsAvailablePdf", typeof(System.Boolean));
            col4.AllowDBNull = true;
            DataColumn col5 = dataTable.Columns.Add("IsAvailablePaper", typeof(System.Boolean));
            col5.AllowDBNull = true;
            DataColumn col6 = dataTable.Columns.Add("IsBorrowed", typeof(System.Boolean));
            col6.AllowDBNull = false;
            DataColumn col7 = dataTable.Columns.Add("User_ID", typeof(System.Int32));
            col7.AllowDBNull = false;
            DataColumn col8 = dataTable.Columns.Add("BorrowDate", typeof(System.DateTime));
            col8.AllowDBNull = true;
            DataColumn col9 = dataTable.Columns.Add("Borrow_Times", typeof(System.Int32));
            col9.AllowDBNull = true;
            DataColumn col10 = dataTable.Columns.Add("IsLost", typeof(System.Boolean));
            col10.AllowDBNull = true;
            DataColumn col11 = dataTable.Columns.Add("Type_ID", typeof(System.Int32));
            col11.AllowDBNull = false;
            DataColumn col12 = dataTable.Columns.Add("Publisher_ID", typeof(System.Int32));
            col12.AllowDBNull = false;
            DataColumn col13 = dataTable.Columns.Add("Papers_no", typeof(System.Int32));
            col13.AllowDBNull = true;
            DataColumn col14 = dataTable.Columns.Add("Introducer_ID", typeof(System.Int32));
            col14.AllowDBNull = true;
            DataColumn col15 = dataTable.Columns.Add("EmployeeI_D", typeof(System.Int32));
            col15.AllowDBNull = false;
            DataColumn col16 = dataTable.Columns.Add("Size", typeof(System.Double));
            col16.AllowDBNull = true;
            DataColumn col17 = dataTable.Columns.Add("Price", typeof(System.Int32));
            col17.AllowDBNull = true;
            DataColumn col18 = dataTable.Columns.Add("Pdf_Link", typeof(System.String));
            col18.AllowDBNull = true;
            DataColumn col19 = dataTable.Columns.Add("Image_ID", typeof(System.Int32));
            col19.AllowDBNull = false;
            DataColumn col20 = dataTable.Columns.Add("ISBN", typeof(System.String));
            col20.AllowDBNull = true;
            DataColumn col21 = dataTable.Columns.Add("CreatedOn", typeof(System.DateTime));
            col21.AllowDBNull = true;
            DataColumn col22 = dataTable.Columns.Add("CreatedBy", typeof(System.Int32));
            col22.AllowDBNull = true;
            DataColumn col23 = dataTable.Columns.Add("UpdatedOn", typeof(System.DateTime));
            col23.AllowDBNull = true;
            DataColumn col24 = dataTable.Columns.Add("UpdatedBy", typeof(System.Int32));
            col24.AllowDBNull = true;
            DataColumn col25 = dataTable.Columns.Add("DeletedOn", typeof(System.DateTime));
            col25.AllowDBNull = true;
            DataColumn col26 = dataTable.Columns.Add("DeletedBy", typeof(System.Int32));
            col26.AllowDBNull = true;

            bulkCopy.ColumnMappings.Add("ID", "ID");
            bulkCopy.ColumnMappings.Add("Name", "Name");
            bulkCopy.ColumnMappings.Add("Publisher", "Publisher");
            bulkCopy.ColumnMappings.Add("Publish_Date", "Publish_Date");
            bulkCopy.ColumnMappings.Add("IsAvailablePdf", "IsAvailablePdf");
            bulkCopy.ColumnMappings.Add("IsAvailablePaper", "IsAvailablePaper");
            bulkCopy.ColumnMappings.Add("IsBorrowed", "IsBorrowed");
            bulkCopy.ColumnMappings.Add("User_ID", "User_ID");
            bulkCopy.ColumnMappings.Add("BorrowDate", "BorrowDate");
            bulkCopy.ColumnMappings.Add("Borrow_Times", "Borrow_Times");
            bulkCopy.ColumnMappings.Add("IsLost", "IsLost");
            bulkCopy.ColumnMappings.Add("Type_ID", "Type_ID");
            bulkCopy.ColumnMappings.Add("Publisher_ID", "Publisher_ID");
            bulkCopy.ColumnMappings.Add("Papers_no", "Papers_no");
            bulkCopy.ColumnMappings.Add("Introducer_ID", "Introducer_ID");
            bulkCopy.ColumnMappings.Add("EmployeeI_D", "EmployeeI_D");
            bulkCopy.ColumnMappings.Add("Size", "Size");
            bulkCopy.ColumnMappings.Add("Price", "Price");
            bulkCopy.ColumnMappings.Add("Pdf_Link", "Pdf_Link");
            bulkCopy.ColumnMappings.Add("Image_ID", "Image_ID");
            bulkCopy.ColumnMappings.Add("ISBN", "ISBN");
            bulkCopy.ColumnMappings.Add("CreatedOn", "CreatedOn");
            bulkCopy.ColumnMappings.Add("CreatedBy", "CreatedBy");
            bulkCopy.ColumnMappings.Add("UpdatedOn", "UpdatedOn");
            bulkCopy.ColumnMappings.Add("UpdatedBy", "UpdatedBy");
            bulkCopy.ColumnMappings.Add("DeletedOn", "DeletedOn");
            bulkCopy.ColumnMappings.Add("DeletedBy", "DeletedBy");

            foreach(Library.BLL.Book entity in entities)
            {
                if (entity.EntityState != EntityState.Added)
                    continue;

                DataRow row = dataTable.NewRow();

                    row["ID"] = entity.ID;

                    row["Name"] = entity.Name;

                    row["Publisher"] = entity.Publisher;

                    row["Publish_Date"] = entity.Publish_Date.HasValue ? (object) entity.Publish_Date  : System.DBNull.Value;

                    row["IsAvailablePdf"] = entity.IsAvailablePdf.HasValue ? (object) entity.IsAvailablePdf  : System.DBNull.Value;

                    row["IsAvailablePaper"] = entity.IsAvailablePaper.HasValue ? (object) entity.IsAvailablePaper  : System.DBNull.Value;

                    row["IsBorrowed"] = entity.IsBorrowed;

                    row["User_ID"] = entity.User_ID;

                    row["BorrowDate"] = entity.BorrowDate.HasValue ? (object) entity.BorrowDate  : System.DBNull.Value;

                    row["Borrow_Times"] = entity.Borrow_Times.HasValue ? (object) entity.Borrow_Times  : System.DBNull.Value;

                    row["IsLost"] = entity.IsLost.HasValue ? (object) entity.IsLost  : System.DBNull.Value;

                    row["Type_ID"] = entity.Type_ID;

                    row["Publisher_ID"] = entity.Publisher_ID;

                    row["Papers_no"] = entity.Papers_no.HasValue ? (object) entity.Papers_no  : System.DBNull.Value;

                    row["Introducer_ID"] = entity.Introducer_ID.HasValue ? (object) entity.Introducer_ID  : System.DBNull.Value;

                    row["EmployeeI_D"] = entity.EmployeeI_D;

                    row["Size"] = entity.Size.HasValue ? (object) entity.Size  : System.DBNull.Value;

                    row["Price"] = entity.Price.HasValue ? (object) entity.Price  : System.DBNull.Value;

                    row["Pdf_Link"] = entity.Pdf_Link;

                    row["Image_ID"] = entity.Image_ID;

                    row["ISBN"] = entity.ISBN;

                    row["CreatedOn"] = entity.CreatedOn.HasValue ? (object) entity.CreatedOn  : System.DBNull.Value;

                    row["CreatedBy"] = entity.CreatedBy.HasValue ? (object) entity.CreatedBy  : System.DBNull.Value;

                    row["UpdatedOn"] = entity.UpdatedOn.HasValue ? (object) entity.UpdatedOn  : System.DBNull.Value;

                    row["UpdatedBy"] = entity.UpdatedBy.HasValue ? (object) entity.UpdatedBy  : System.DBNull.Value;

                    row["DeletedOn"] = entity.DeletedOn.HasValue ? (object) entity.DeletedOn  : System.DBNull.Value;

                    row["DeletedBy"] = entity.DeletedBy.HasValue ? (object) entity.DeletedBy  : System.DBNull.Value;

                dataTable.Rows.Add(row);
            }

            // send the data to the server
            bulkCopy.WriteToServer(dataTable);

            // update back the state
            foreach(Library.BLL.Book entity in entities)
            {
                if (entity.EntityState != EntityState.Added)
                    continue;

                entity.AcceptChanges();
            }
        }
        /// <summary>
        /// 	Update an existing row in the datasource.
        /// </summary>
        /// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
        /// <param name="entity">Library.BLL.Course object to update.</param>
        /// <remarks>
        ///		After updating the datasource, the Library.BLL.Course object will be updated
        /// 	to refelect any changes made by the datasource. (ie: identity or computed columns)
        /// </remarks>
        /// <returns>Returns true if operation is successful.</returns>
        /// <exception cref="System.Exception">The command could not be executed.</exception>
        /// <exception cref="System.Data.DataException">The <paramref name="transactionManager"/> is not open.</exception>
        /// <exception cref="System.Data.Common.DbException">The command could not be executed.</exception>
        public override bool Update(TransactionManager transactionManager, Library.BLL.Course entity)
        {
            SqlDatabase database = new SqlDatabase(this._connectionString);
            DbCommand commandWrapper = StoredProcedureProvider.GetCommandWrapper(database, "dbo.Course_Update", _useStoredProcedure);

            database.AddInParameter(commandWrapper, "@ID", DbType.Int32, entity.ID );
            database.AddInParameter(commandWrapper, "@Course_Name", DbType.String, entity.Course_Name );
            database.AddInParameter(commandWrapper, "@Course_Scope", DbType.Int32, entity.Course_Scope );
            database.AddInParameter(commandWrapper, "@Duration", DbType.Int32, entity.Duration );
            database.AddInParameter(commandWrapper, "@DurationType_ID", DbType.Int32, entity.DurationType_ID );
            database.AddInParameter(commandWrapper, "@Is_Deleted", DbType.Boolean, (entity.Is_Deleted.HasValue ? (object) entity.Is_Deleted : System.DBNull.Value) );
            database.AddInParameter(commandWrapper, "@CreatedOn", DbType.DateTime, (entity.CreatedOn.HasValue ? (object) entity.CreatedOn : System.DBNull.Value) );
            database.AddInParameter(commandWrapper, "@CreatedBy", DbType.Int32, (entity.CreatedBy.HasValue ? (object) entity.CreatedBy : System.DBNull.Value) );
            database.AddInParameter(commandWrapper, "@UpdatedOn", DbType.DateTime, (entity.UpdatedOn.HasValue ? (object) entity.UpdatedOn : System.DBNull.Value) );
            database.AddInParameter(commandWrapper, "@UpdatedBy", DbType.Int32, (entity.UpdatedBy.HasValue ? (object) entity.UpdatedBy : System.DBNull.Value) );
            database.AddInParameter(commandWrapper, "@DeletedOn", DbType.DateTime, (entity.DeletedOn.HasValue ? (object) entity.DeletedOn : System.DBNull.Value) );
            database.AddInParameter(commandWrapper, "@DeletedBy", DbType.Int32, (entity.DeletedBy.HasValue ? (object) entity.DeletedBy : System.DBNull.Value) );

            int results = 0;

            //Provider Data Requesting Command Event
            OnDataRequesting(new CommandEventArgs(commandWrapper, "Update", entity));

            if (transactionManager != null)
            {
                results = Utility.ExecuteNonQuery(transactionManager, commandWrapper);
            }
            else
            {
                results = Utility.ExecuteNonQuery(database,commandWrapper);
            }

            //Stop Tracking Now that it has been updated and persisted.
            if (DataRepository.Provider.EnableEntityTracking)
            {
                EntityManager.StopTracking(entity.EntityTrackingKey);
            }

            entity.AcceptChanges();

            //Provider Data Requested Command Event
            OnDataRequested(new CommandEventArgs(commandWrapper, "Update", entity));

            return Convert.ToBoolean(results);
        }
        /// <summary>
        /// 	Update an existing row in the datasource.
        /// </summary>
        /// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
        /// <param name="entity">Library.BLL.Book object to update.</param>
        /// <remarks>
        ///		After updating the datasource, the Library.BLL.Book object will be updated
        /// 	to refelect any changes made by the datasource. (ie: identity or computed columns)
        /// </remarks>
        /// <returns>Returns true if operation is successful.</returns>
        /// <exception cref="System.Exception">The command could not be executed.</exception>
        /// <exception cref="System.Data.DataException">The <paramref name="transactionManager"/> is not open.</exception>
        /// <exception cref="System.Data.Common.DbException">The command could not be executed.</exception>
        public override bool Update(TransactionManager transactionManager, Library.BLL.Book entity)
        {
            SqlDatabase database = new SqlDatabase(this._connectionString);
            DbCommand commandWrapper = StoredProcedureProvider.GetCommandWrapper(database, "dbo.Book_Update", _useStoredProcedure);

            database.AddInParameter(commandWrapper, "@ID", DbType.Int32, entity.ID );
            database.AddInParameter(commandWrapper, "@Name", DbType.String, entity.Name );
            database.AddInParameter(commandWrapper, "@Publisher", DbType.String, entity.Publisher );
            database.AddInParameter(commandWrapper, "@Publish_Date", DbType.Date, (entity.Publish_Date.HasValue ? (object) entity.Publish_Date : System.DBNull.Value) );
            database.AddInParameter(commandWrapper, "@IsAvailablePdf", DbType.Boolean, (entity.IsAvailablePdf.HasValue ? (object) entity.IsAvailablePdf : System.DBNull.Value) );
            database.AddInParameter(commandWrapper, "@IsAvailablePaper", DbType.Boolean, (entity.IsAvailablePaper.HasValue ? (object) entity.IsAvailablePaper : System.DBNull.Value) );
            database.AddInParameter(commandWrapper, "@IsBorrowed", DbType.Boolean, entity.IsBorrowed );
            database.AddInParameter(commandWrapper, "@User_ID", DbType.Int32, entity.User_ID );
            database.AddInParameter(commandWrapper, "@BorrowDate", DbType.Date, (entity.BorrowDate.HasValue ? (object) entity.BorrowDate : System.DBNull.Value) );
            database.AddInParameter(commandWrapper, "@Borrow_Times", DbType.Int32, (entity.Borrow_Times.HasValue ? (object) entity.Borrow_Times : System.DBNull.Value) );
            database.AddInParameter(commandWrapper, "@IsLost", DbType.Boolean, (entity.IsLost.HasValue ? (object) entity.IsLost : System.DBNull.Value) );
            database.AddInParameter(commandWrapper, "@Type_ID", DbType.Int32, entity.Type_ID );
            database.AddInParameter(commandWrapper, "@Publisher_ID", DbType.Int32, entity.Publisher_ID );
            database.AddInParameter(commandWrapper, "@Papers_no", DbType.Int32, (entity.Papers_no.HasValue ? (object) entity.Papers_no : System.DBNull.Value) );
            database.AddInParameter(commandWrapper, "@Introducer_ID", DbType.Int32, (entity.Introducer_ID.HasValue ? (object) entity.Introducer_ID : System.DBNull.Value) );
            database.AddInParameter(commandWrapper, "@EmployeeI_D", DbType.Int32, entity.EmployeeI_D );
            database.AddInParameter(commandWrapper, "@Size", DbType.Double, (entity.Size.HasValue ? (object) entity.Size : System.DBNull.Value) );
            database.AddInParameter(commandWrapper, "@Price", DbType.Int32, (entity.Price.HasValue ? (object) entity.Price : System.DBNull.Value) );
            database.AddInParameter(commandWrapper, "@Pdf_Link", DbType.String, entity.Pdf_Link );
            database.AddInParameter(commandWrapper, "@Image_ID", DbType.Int32, entity.Image_ID );
            database.AddInParameter(commandWrapper, "@ISBN", DbType.String, entity.ISBN );
            database.AddInParameter(commandWrapper, "@CreatedOn", DbType.DateTime, (entity.CreatedOn.HasValue ? (object) entity.CreatedOn : System.DBNull.Value) );
            database.AddInParameter(commandWrapper, "@CreatedBy", DbType.Int32, (entity.CreatedBy.HasValue ? (object) entity.CreatedBy : System.DBNull.Value) );
            database.AddInParameter(commandWrapper, "@UpdatedOn", DbType.DateTime, (entity.UpdatedOn.HasValue ? (object) entity.UpdatedOn : System.DBNull.Value) );
            database.AddInParameter(commandWrapper, "@UpdatedBy", DbType.Int32, (entity.UpdatedBy.HasValue ? (object) entity.UpdatedBy : System.DBNull.Value) );
            database.AddInParameter(commandWrapper, "@DeletedOn", DbType.DateTime, (entity.DeletedOn.HasValue ? (object) entity.DeletedOn : System.DBNull.Value) );
            database.AddInParameter(commandWrapper, "@DeletedBy", DbType.Int32, (entity.DeletedBy.HasValue ? (object) entity.DeletedBy : System.DBNull.Value) );

            int results = 0;

            //Provider Data Requesting Command Event
            OnDataRequesting(new CommandEventArgs(commandWrapper, "Update", entity));

            if (transactionManager != null)
            {
                results = Utility.ExecuteNonQuery(transactionManager, commandWrapper);
            }
            else
            {
                results = Utility.ExecuteNonQuery(database,commandWrapper);
            }

            //Stop Tracking Now that it has been updated and persisted.
            if (DataRepository.Provider.EnableEntityTracking)
            {
                EntityManager.StopTracking(entity.EntityTrackingKey);
            }

            entity.AcceptChanges();

            //Provider Data Requested Command Event
            OnDataRequested(new CommandEventArgs(commandWrapper, "Update", entity));

            return Convert.ToBoolean(results);
        }
        /// <summary>
        /// Lets you efficiently bulk insert many entities to the database.
        /// </summary>
        /// <param name="transactionManager">The transaction manager.</param>
        /// <param name="entities">The entities.</param>
        /// <remarks>
        ///		After inserting into the datasource, the Library.BLL.Publisher object will be updated
        /// 	to refelect any changes made by the datasource. (ie: identity or computed columns)
        /// </remarks>	
        public override void BulkInsert(TransactionManager transactionManager, TList<Library.BLL.Publisher> entities)
        {
            //System.Data.SqlClient.SqlBulkCopy bulkCopy = new System.Data.SqlClient.SqlBulkCopy(this._connectionString, System.Data.SqlClient.SqlBulkCopyOptions.CheckConstraints); //, null);

            System.Data.SqlClient.SqlBulkCopy bulkCopy = null;

            if (transactionManager != null && transactionManager.IsOpen)
            {
                System.Data.SqlClient.SqlConnection cnx = transactionManager.TransactionObject.Connection as System.Data.SqlClient.SqlConnection;
                System.Data.SqlClient.SqlTransaction transaction = transactionManager.TransactionObject as System.Data.SqlClient.SqlTransaction;
                bulkCopy = new System.Data.SqlClient.SqlBulkCopy(cnx, System.Data.SqlClient.SqlBulkCopyOptions.CheckConstraints, transaction); //, null);
            }
            else
            {
                bulkCopy = new System.Data.SqlClient.SqlBulkCopy(this._connectionString, System.Data.SqlClient.SqlBulkCopyOptions.CheckConstraints); //, null);
            }

            bulkCopy.BulkCopyTimeout = 360;
            bulkCopy.DestinationTableName = "Publisher";

            DataTable dataTable = new DataTable();
            DataColumn col0 = dataTable.Columns.Add("ID", typeof(System.Int32));
            col0.AllowDBNull = false;
            DataColumn col1 = dataTable.Columns.Add("Name", typeof(System.String));
            col1.AllowDBNull = false;
            DataColumn col2 = dataTable.Columns.Add("Mobile", typeof(System.String));
            col2.AllowDBNull = true;
            DataColumn col3 = dataTable.Columns.Add("Email", typeof(System.String));
            col3.AllowDBNull = true;
            DataColumn col4 = dataTable.Columns.Add("Website", typeof(System.String));
            col4.AllowDBNull = true;
            DataColumn col5 = dataTable.Columns.Add("FounedOn", typeof(System.DateTime));
            col5.AllowDBNull = true;
            DataColumn col6 = dataTable.Columns.Add("Country", typeof(System.String));
            col6.AllowDBNull = true;
            DataColumn col7 = dataTable.Columns.Add("City", typeof(System.String));
            col7.AllowDBNull = true;
            DataColumn col8 = dataTable.Columns.Add("Address", typeof(System.String));
            col8.AllowDBNull = true;

            bulkCopy.ColumnMappings.Add("ID", "ID");
            bulkCopy.ColumnMappings.Add("Name", "Name");
            bulkCopy.ColumnMappings.Add("Mobile", "Mobile");
            bulkCopy.ColumnMappings.Add("Email", "Email");
            bulkCopy.ColumnMappings.Add("Website", "Website");
            bulkCopy.ColumnMappings.Add("FounedOn", "FounedOn");
            bulkCopy.ColumnMappings.Add("Country", "Country");
            bulkCopy.ColumnMappings.Add("City", "City");
            bulkCopy.ColumnMappings.Add("Address", "Address");

            foreach(Library.BLL.Publisher entity in entities)
            {
                if (entity.EntityState != EntityState.Added)
                    continue;

                DataRow row = dataTable.NewRow();

                    row["ID"] = entity.ID;

                    row["Name"] = entity.Name;

                    row["Mobile"] = entity.Mobile;

                    row["Email"] = entity.Email;

                    row["Website"] = entity.Website;

                    row["FounedOn"] = entity.FounedOn.HasValue ? (object) entity.FounedOn  : System.DBNull.Value;

                    row["Country"] = entity.Country;

                    row["City"] = entity.City;

                    row["Address"] = entity.Address;

                dataTable.Rows.Add(row);
            }

            // send the data to the server
            bulkCopy.WriteToServer(dataTable);

            // update back the state
            foreach(Library.BLL.Publisher entity in entities)
            {
                if (entity.EntityState != EntityState.Added)
                    continue;

                entity.AcceptChanges();
            }
        }
        /// <summary>
        /// Lets you efficiently bulk insert many entities to the database.
        /// </summary>
        /// <param name="transactionManager">The transaction manager.</param>
        /// <param name="entities">The entities.</param>
        /// <remarks>
        ///		After inserting into the datasource, the Library.BLL.BookImage object will be updated
        /// 	to refelect any changes made by the datasource. (ie: identity or computed columns)
        /// </remarks>	
        public override void BulkInsert(TransactionManager transactionManager, TList<Library.BLL.BookImage> entities)
        {
            //System.Data.SqlClient.SqlBulkCopy bulkCopy = new System.Data.SqlClient.SqlBulkCopy(this._connectionString, System.Data.SqlClient.SqlBulkCopyOptions.CheckConstraints); //, null);

            System.Data.SqlClient.SqlBulkCopy bulkCopy = null;

            if (transactionManager != null && transactionManager.IsOpen)
            {
                System.Data.SqlClient.SqlConnection cnx = transactionManager.TransactionObject.Connection as System.Data.SqlClient.SqlConnection;
                System.Data.SqlClient.SqlTransaction transaction = transactionManager.TransactionObject as System.Data.SqlClient.SqlTransaction;
                bulkCopy = new System.Data.SqlClient.SqlBulkCopy(cnx, System.Data.SqlClient.SqlBulkCopyOptions.CheckConstraints, transaction); //, null);
            }
            else
            {
                bulkCopy = new System.Data.SqlClient.SqlBulkCopy(this._connectionString, System.Data.SqlClient.SqlBulkCopyOptions.CheckConstraints); //, null);
            }

            bulkCopy.BulkCopyTimeout = 360;
            bulkCopy.DestinationTableName = "BookImage";

            DataTable dataTable = new DataTable();
            DataColumn col0 = dataTable.Columns.Add("ID", typeof(System.Int32));
            col0.AllowDBNull = false;
            DataColumn col1 = dataTable.Columns.Add("Name", typeof(System.String));
            col1.AllowDBNull = false;
            DataColumn col2 = dataTable.Columns.Add("Format", typeof(System.String));
            col2.AllowDBNull = true;
            DataColumn col3 = dataTable.Columns.Add("Size", typeof(System.String));
            col3.AllowDBNull = true;
            DataColumn col4 = dataTable.Columns.Add("Link", typeof(System.String));
            col4.AllowDBNull = true;
            DataColumn col5 = dataTable.Columns.Add("IsAvailable", typeof(System.String));
            col5.AllowDBNull = true;

            bulkCopy.ColumnMappings.Add("ID", "ID");
            bulkCopy.ColumnMappings.Add("Name", "Name");
            bulkCopy.ColumnMappings.Add("Format", "Format");
            bulkCopy.ColumnMappings.Add("Size", "Size");
            bulkCopy.ColumnMappings.Add("Link", "Link");
            bulkCopy.ColumnMappings.Add("IsAvailable", "IsAvailable");

            foreach(Library.BLL.BookImage entity in entities)
            {
                if (entity.EntityState != EntityState.Added)
                    continue;

                DataRow row = dataTable.NewRow();

                    row["ID"] = entity.ID;

                    row["Name"] = entity.Name;

                    row["Format"] = entity.Format;

                    row["Size"] = entity.Size;

                    row["Link"] = entity.Link;

                    row["IsAvailable"] = entity.IsAvailable;

                dataTable.Rows.Add(row);
            }

            // send the data to the server
            bulkCopy.WriteToServer(dataTable);

            // update back the state
            foreach(Library.BLL.BookImage entity in entities)
            {
                if (entity.EntityState != EntityState.Added)
                    continue;

                entity.AcceptChanges();
            }
        }
        /// <summary>
        /// 	Inserts a Library.BLL.Publisher object into the datasource using a transaction.
        /// </summary>
        /// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
        /// <param name="entity">Library.BLL.Publisher object to insert.</param>
        /// <remarks>
        ///		After inserting into the datasource, the Library.BLL.Publisher object will be updated
        /// 	to refelect any changes made by the datasource. (ie: identity or computed columns)
        /// </remarks>	
        /// <returns>Returns true if operation is successful.</returns>
        /// <exception cref="System.Exception">The command could not be executed.</exception>
        /// <exception cref="System.Data.DataException">The <paramref name="transactionManager"/> is not open.</exception>
        /// <exception cref="System.Data.Common.DbException">The command could not be executed.</exception>
        public override bool Insert(TransactionManager transactionManager, Library.BLL.Publisher entity)
        {
            SqlDatabase database = new SqlDatabase(this._connectionString);
            DbCommand commandWrapper = StoredProcedureProvider.GetCommandWrapper(database, "dbo.Publisher_Insert", _useStoredProcedure);

            database.AddOutParameter(commandWrapper, "@ID", DbType.Int32, 4);
            database.AddInParameter(commandWrapper, "@Name", DbType.String, entity.Name );
            database.AddInParameter(commandWrapper, "@Mobile", DbType.StringFixedLength, entity.Mobile );
            database.AddInParameter(commandWrapper, "@Email", DbType.String, entity.Email );
            database.AddInParameter(commandWrapper, "@Website", DbType.String, entity.Website );
            database.AddInParameter(commandWrapper, "@FounedOn", DbType.Date, (entity.FounedOn.HasValue ? (object) entity.FounedOn  : System.DBNull.Value));
            database.AddInParameter(commandWrapper, "@Country", DbType.String, entity.Country );
            database.AddInParameter(commandWrapper, "@City", DbType.String, entity.City );
            database.AddInParameter(commandWrapper, "@Address", DbType.String, entity.Address );

            int results = 0;

            //Provider Data Requesting Command Event
            OnDataRequesting(new CommandEventArgs(commandWrapper, "Insert", entity));

            if (transactionManager != null)
            {
                results = Utility.ExecuteNonQuery(transactionManager, commandWrapper);
            }
            else
            {
                results = Utility.ExecuteNonQuery(database,commandWrapper);
            }

            object _iD = database.GetParameterValue(commandWrapper, "@ID");
            entity.ID = (System.Int32)_iD;

            entity.AcceptChanges();

            //Provider Data Requested Command Event
            OnDataRequested(new CommandEventArgs(commandWrapper, "Insert", entity));

            return Convert.ToBoolean(results);
        }
        /// <summary>
        /// 	Returns rows meeting the whereClause condition from the DataSource.
        /// </summary>
        /// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
        /// <param name="whereClause">Specifies the condition for the rows returned by a query (Name='John Doe', Name='John Doe' AND Id='1', Name='John Doe' OR Id='1').</param>
        /// <param name="start">Row number at which to start reading.</param>
        /// <param name="pageLength">Number of rows to return.</param>
        /// <param name="count">out. The number of rows that match this query.</param>
        /// <remarks>Operators must be capitalized (OR, AND).</remarks>
        /// <returns>Returns a typed collection of Library.BLL.BookImage objects.</returns>
        public override TList<BookImage> Find(TransactionManager transactionManager, string whereClause, int start, int pageLength, out int count)
        {
            count = -1;
            if (whereClause.IndexOf(";") > -1)
                return new TList<BookImage>();

            SqlDatabase database = new SqlDatabase(this._connectionString);
            DbCommand commandWrapper = StoredProcedureProvider.GetCommandWrapper(database, "dbo.BookImage_Find", _useStoredProcedure);

            bool searchUsingOR = false;
            if (whereClause.IndexOf(" OR ") > 0) // did they want to do "a=b OR c=d OR..."?
            searchUsingOR = true;

            database.AddInParameter(commandWrapper, "@SearchUsingOR", DbType.Boolean, searchUsingOR);

            database.AddInParameter(commandWrapper, "@ID", DbType.Int32, DBNull.Value);
            database.AddInParameter(commandWrapper, "@Name", DbType.String, DBNull.Value);
            database.AddInParameter(commandWrapper, "@Format", DbType.String, DBNull.Value);
            database.AddInParameter(commandWrapper, "@Size", DbType.String, DBNull.Value);
            database.AddInParameter(commandWrapper, "@Link", DbType.String, DBNull.Value);
            database.AddInParameter(commandWrapper, "@IsAvailable", DbType.String, DBNull.Value);

            // replace all instances of 'AND' and 'OR' because we already set searchUsingOR
            whereClause = whereClause.Replace(" AND ", "|").Replace(" OR ", "|") ;
            string[] clauses = whereClause.ToLower().Split('|');

            // Here's what's going on below: Find a field, then to get the value we
            // drop the field name from the front, trim spaces, drop the '=' sign,
            // trim more spaces, and drop any outer single quotes.
            // Now handles the case when two fields start off the same way - like "Friendly='Yes' AND Friend='john'"

            char[] equalSign = {'='};
            char[] singleQuote = {'\''};
               		foreach (string clause in clauses)
            {
                if (clause.Trim().StartsWith("id ") || clause.Trim().StartsWith("id="))
                {
                    database.SetParameterValue(commandWrapper, "@ID",
                        clause.Trim().Remove(0,2).Trim().TrimStart(equalSign).Trim().Trim(singleQuote));
                    continue;
                }
                if (clause.Trim().StartsWith("name ") || clause.Trim().StartsWith("name="))
                {
                    database.SetParameterValue(commandWrapper, "@Name",
                        clause.Trim().Remove(0,4).Trim().TrimStart(equalSign).Trim().Trim(singleQuote));
                    continue;
                }
                if (clause.Trim().StartsWith("format ") || clause.Trim().StartsWith("format="))
                {
                    database.SetParameterValue(commandWrapper, "@Format",
                        clause.Trim().Remove(0,6).Trim().TrimStart(equalSign).Trim().Trim(singleQuote));
                    continue;
                }
                if (clause.Trim().StartsWith("size ") || clause.Trim().StartsWith("size="))
                {
                    database.SetParameterValue(commandWrapper, "@Size",
                        clause.Trim().Remove(0,4).Trim().TrimStart(equalSign).Trim().Trim(singleQuote));
                    continue;
                }
                if (clause.Trim().StartsWith("link ") || clause.Trim().StartsWith("link="))
                {
                    database.SetParameterValue(commandWrapper, "@Link",
                        clause.Trim().Remove(0,4).Trim().TrimStart(equalSign).Trim().Trim(singleQuote));
                    continue;
                }
                if (clause.Trim().StartsWith("isavailable ") || clause.Trim().StartsWith("isavailable="))
                {
                    database.SetParameterValue(commandWrapper, "@IsAvailable",
                        clause.Trim().Remove(0,11).Trim().TrimStart(equalSign).Trim().Trim(singleQuote));
                    continue;
                }

                throw new ArgumentException("Unable to use this part of the where clause in this version of Find: " + clause);
            }

            IDataReader reader = null;
            //Create Collection
            TList<BookImage> rows = new TList<BookImage>();

            try
            {
                //Provider Data Requesting Command Event
                OnDataRequesting(new CommandEventArgs(commandWrapper, "Find", rows));

                if (transactionManager != null)
                {
                    reader = Utility.ExecuteReader(transactionManager, commandWrapper);
                }
                else
                {
                    reader = Utility.ExecuteReader(database, commandWrapper);
                }

                Fill(reader, rows, start, pageLength);

                if(reader.NextResult())
                {
                    if(reader.Read())
                    {
                        count = reader.GetInt32(0);
                    }
                }

                //Provider Data Requested Command Event
                OnDataRequested(new CommandEventArgs(commandWrapper, "Find", rows));
            }
            finally
            {
                if (reader != null)
                    reader.Close();

                commandWrapper = null;
            }
            return rows;
        }
        /// <summary>
        /// 	Update an existing row in the datasource.
        /// </summary>
        /// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
        /// <param name="entity">Library.BLL.Publisher object to update.</param>
        /// <remarks>
        ///		After updating the datasource, the Library.BLL.Publisher object will be updated
        /// 	to refelect any changes made by the datasource. (ie: identity or computed columns)
        /// </remarks>
        /// <returns>Returns true if operation is successful.</returns>
        /// <exception cref="System.Exception">The command could not be executed.</exception>
        /// <exception cref="System.Data.DataException">The <paramref name="transactionManager"/> is not open.</exception>
        /// <exception cref="System.Data.Common.DbException">The command could not be executed.</exception>
        public override bool Update(TransactionManager transactionManager, Library.BLL.Publisher entity)
        {
            SqlDatabase database = new SqlDatabase(this._connectionString);
            DbCommand commandWrapper = StoredProcedureProvider.GetCommandWrapper(database, "dbo.Publisher_Update", _useStoredProcedure);

            database.AddInParameter(commandWrapper, "@ID", DbType.Int32, entity.ID );
            database.AddInParameter(commandWrapper, "@Name", DbType.String, entity.Name );
            database.AddInParameter(commandWrapper, "@Mobile", DbType.StringFixedLength, entity.Mobile );
            database.AddInParameter(commandWrapper, "@Email", DbType.String, entity.Email );
            database.AddInParameter(commandWrapper, "@Website", DbType.String, entity.Website );
            database.AddInParameter(commandWrapper, "@FounedOn", DbType.Date, (entity.FounedOn.HasValue ? (object) entity.FounedOn : System.DBNull.Value) );
            database.AddInParameter(commandWrapper, "@Country", DbType.String, entity.Country );
            database.AddInParameter(commandWrapper, "@City", DbType.String, entity.City );
            database.AddInParameter(commandWrapper, "@Address", DbType.String, entity.Address );

            int results = 0;

            //Provider Data Requesting Command Event
            OnDataRequesting(new CommandEventArgs(commandWrapper, "Update", entity));

            if (transactionManager != null)
            {
                results = Utility.ExecuteNonQuery(transactionManager, commandWrapper);
            }
            else
            {
                results = Utility.ExecuteNonQuery(database,commandWrapper);
            }

            //Stop Tracking Now that it has been updated and persisted.
            if (DataRepository.Provider.EnableEntityTracking)
            {
                EntityManager.StopTracking(entity.EntityTrackingKey);
            }

            entity.AcceptChanges();

            //Provider Data Requested Command Event
            OnDataRequested(new CommandEventArgs(commandWrapper, "Update", entity));

            return Convert.ToBoolean(results);
        }
        /// <summary>
        /// 	Gets All rows from the DataSource.
        /// </summary>
        /// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
        /// <param name="start">Row number at which to start reading.</param>
        /// <param name="pageLength">Number of rows to return.</param>
        /// <param name="count">out. The number of rows that match this query.</param>
        /// <remarks></remarks>
        /// <returns>Returns a typed collection of Library.BLL.BookImage objects.</returns>
        /// <exception cref="System.Exception">The command could not be executed.</exception>
        /// <exception cref="System.Data.DataException">The <paramref name="transactionManager"/> is not open.</exception>
        /// <exception cref="System.Data.Common.DbException">The command could not be executed.</exception>
        public override TList<BookImage> GetAll(TransactionManager transactionManager, int start, int pageLength, out int count)
        {
            SqlDatabase database = new SqlDatabase(this._connectionString);
            DbCommand commandWrapper = StoredProcedureProvider.GetCommandWrapper(database, "dbo.BookImage_Get_List", _useStoredProcedure);

            IDataReader reader = null;

            //Create Collection
            TList<BookImage> rows = new TList<BookImage>();

            try
            {
                //Provider Data Requesting Command Event
                OnDataRequesting(new CommandEventArgs(commandWrapper, "GetAll", rows));

                if (transactionManager != null)
                {
                    reader = Utility.ExecuteReader(transactionManager, commandWrapper);
                }
                else
                {
                    reader = Utility.ExecuteReader(database, commandWrapper);
                }

                Fill(reader, rows, start, pageLength);
                count = -1;
                if(reader.NextResult())
                {
                    if(reader.Read())
                    {
                        count = reader.GetInt32(0);
                    }
                }

                //Provider Data Requested Command Event
                OnDataRequested(new CommandEventArgs(commandWrapper, "GetAll", rows));
            }
            finally
            {
                if (reader != null)
                    reader.Close();

                commandWrapper = null;
            }
            return rows;
        }
        /// <summary>
        /// Lets you efficiently bulk insert many entities to the database.
        /// </summary>
        /// <param name="transactionManager">The transaction manager.</param>
        /// <param name="entities">The entities.</param>
        /// <remarks>
        ///		After inserting into the datasource, the Library.BLL.Employee object will be updated
        /// 	to refelect any changes made by the datasource. (ie: identity or computed columns)
        /// </remarks>	
        public override void BulkInsert(TransactionManager transactionManager, TList<Library.BLL.Employee> entities)
        {
            //System.Data.SqlClient.SqlBulkCopy bulkCopy = new System.Data.SqlClient.SqlBulkCopy(this._connectionString, System.Data.SqlClient.SqlBulkCopyOptions.CheckConstraints); //, null);

            System.Data.SqlClient.SqlBulkCopy bulkCopy = null;

            if (transactionManager != null && transactionManager.IsOpen)
            {
                System.Data.SqlClient.SqlConnection cnx = transactionManager.TransactionObject.Connection as System.Data.SqlClient.SqlConnection;
                System.Data.SqlClient.SqlTransaction transaction = transactionManager.TransactionObject as System.Data.SqlClient.SqlTransaction;
                bulkCopy = new System.Data.SqlClient.SqlBulkCopy(cnx, System.Data.SqlClient.SqlBulkCopyOptions.CheckConstraints, transaction); //, null);
            }
            else
            {
                bulkCopy = new System.Data.SqlClient.SqlBulkCopy(this._connectionString, System.Data.SqlClient.SqlBulkCopyOptions.CheckConstraints); //, null);
            }

            bulkCopy.BulkCopyTimeout = 360;
            bulkCopy.DestinationTableName = "Employee";

            DataTable dataTable = new DataTable();
            DataColumn col0 = dataTable.Columns.Add("ID", typeof(System.Int32));
            col0.AllowDBNull = false;
            DataColumn col1 = dataTable.Columns.Add("UserName", typeof(System.String));
            col1.AllowDBNull = true;
            DataColumn col2 = dataTable.Columns.Add("Password", typeof(System.String));
            col2.AllowDBNull = true;
            DataColumn col3 = dataTable.Columns.Add("Last_Login", typeof(System.DateTime));
            col3.AllowDBNull = true;
            DataColumn col4 = dataTable.Columns.Add("Last_Logout", typeof(System.DateTime));
            col4.AllowDBNull = false;
            DataColumn col5 = dataTable.Columns.Add("Is_Online", typeof(System.Boolean));
            col5.AllowDBNull = true;
            DataColumn col6 = dataTable.Columns.Add("Is_Active", typeof(System.Boolean));
            col6.AllowDBNull = true;
            DataColumn col7 = dataTable.Columns.Add("Is_Admin", typeof(System.Boolean));
            col7.AllowDBNull = true;
            DataColumn col8 = dataTable.Columns.Add("First_Name", typeof(System.String));
            col8.AllowDBNull = false;
            DataColumn col9 = dataTable.Columns.Add("Last_Name", typeof(System.String));
            col9.AllowDBNull = false;
            DataColumn col10 = dataTable.Columns.Add("Email", typeof(System.String));
            col10.AllowDBNull = false;
            DataColumn col11 = dataTable.Columns.Add("Country", typeof(System.String));
            col11.AllowDBNull = false;
            DataColumn col12 = dataTable.Columns.Add("City", typeof(System.String));
            col12.AllowDBNull = true;
            DataColumn col13 = dataTable.Columns.Add("Address", typeof(System.String));
            col13.AllowDBNull = true;
            DataColumn col14 = dataTable.Columns.Add("Mobile", typeof(System.String));
            col14.AllowDBNull = false;
            DataColumn col15 = dataTable.Columns.Add("Phone", typeof(System.String));
            col15.AllowDBNull = true;
            DataColumn col16 = dataTable.Columns.Add("Postion", typeof(System.String));
            col16.AllowDBNull = true;
            DataColumn col17 = dataTable.Columns.Add("Is_Deleted", typeof(System.Boolean));
            col17.AllowDBNull = true;
            DataColumn col18 = dataTable.Columns.Add("CreatedOn", typeof(System.DateTime));
            col18.AllowDBNull = true;
            DataColumn col19 = dataTable.Columns.Add("CreatedBy", typeof(System.Int32));
            col19.AllowDBNull = true;
            DataColumn col20 = dataTable.Columns.Add("UpdatedOn", typeof(System.DateTime));
            col20.AllowDBNull = true;
            DataColumn col21 = dataTable.Columns.Add("UpdatedBy", typeof(System.Int32));
            col21.AllowDBNull = true;
            DataColumn col22 = dataTable.Columns.Add("DeletedOn", typeof(System.DateTime));
            col22.AllowDBNull = true;
            DataColumn col23 = dataTable.Columns.Add("DeletedBy", typeof(System.Int32));
            col23.AllowDBNull = true;

            bulkCopy.ColumnMappings.Add("ID", "ID");
            bulkCopy.ColumnMappings.Add("UserName", "UserName");
            bulkCopy.ColumnMappings.Add("Password", "Password");
            bulkCopy.ColumnMappings.Add("Last_Login", "Last_Login");
            bulkCopy.ColumnMappings.Add("Last_Logout", "Last_Logout");
            bulkCopy.ColumnMappings.Add("Is_Online", "Is_Online");
            bulkCopy.ColumnMappings.Add("Is_Active", "Is_Active");
            bulkCopy.ColumnMappings.Add("Is_Admin", "Is_Admin");
            bulkCopy.ColumnMappings.Add("First_Name", "First_Name");
            bulkCopy.ColumnMappings.Add("Last_Name", "Last_Name");
            bulkCopy.ColumnMappings.Add("Email", "Email");
            bulkCopy.ColumnMappings.Add("Country", "Country");
            bulkCopy.ColumnMappings.Add("City", "City");
            bulkCopy.ColumnMappings.Add("Address", "Address");
            bulkCopy.ColumnMappings.Add("Mobile", "Mobile");
            bulkCopy.ColumnMappings.Add("Phone", "Phone");
            bulkCopy.ColumnMappings.Add("Postion", "Postion");
            bulkCopy.ColumnMappings.Add("Is_Deleted", "Is_Deleted");
            bulkCopy.ColumnMappings.Add("CreatedOn", "CreatedOn");
            bulkCopy.ColumnMappings.Add("CreatedBy", "CreatedBy");
            bulkCopy.ColumnMappings.Add("UpdatedOn", "UpdatedOn");
            bulkCopy.ColumnMappings.Add("UpdatedBy", "UpdatedBy");
            bulkCopy.ColumnMappings.Add("DeletedOn", "DeletedOn");
            bulkCopy.ColumnMappings.Add("DeletedBy", "DeletedBy");

            foreach(Library.BLL.Employee entity in entities)
            {
                if (entity.EntityState != EntityState.Added)
                    continue;

                DataRow row = dataTable.NewRow();

                    row["ID"] = entity.ID;

                    row["UserName"] = entity.UserName;

                    row["Password"] = entity.Password;

                    row["Last_Login"] = entity.Last_Login.HasValue ? (object) entity.Last_Login  : System.DBNull.Value;

                    row["Last_Logout"] = entity.Last_Logout;

                    row["Is_Online"] = entity.Is_Online.HasValue ? (object) entity.Is_Online  : System.DBNull.Value;

                    row["Is_Active"] = entity.Is_Active.HasValue ? (object) entity.Is_Active  : System.DBNull.Value;

                    row["Is_Admin"] = entity.Is_Admin.HasValue ? (object) entity.Is_Admin  : System.DBNull.Value;

                    row["First_Name"] = entity.First_Name;

                    row["Last_Name"] = entity.Last_Name;

                    row["Email"] = entity.Email;

                    row["Country"] = entity.Country;

                    row["City"] = entity.City;

                    row["Address"] = entity.Address;

                    row["Mobile"] = entity.Mobile;

                    row["Phone"] = entity.Phone;

                    row["Postion"] = entity.Postion;

                    row["Is_Deleted"] = entity.Is_Deleted.HasValue ? (object) entity.Is_Deleted  : System.DBNull.Value;

                    row["CreatedOn"] = entity.CreatedOn.HasValue ? (object) entity.CreatedOn  : System.DBNull.Value;

                    row["CreatedBy"] = entity.CreatedBy.HasValue ? (object) entity.CreatedBy  : System.DBNull.Value;

                    row["UpdatedOn"] = entity.UpdatedOn.HasValue ? (object) entity.UpdatedOn  : System.DBNull.Value;

                    row["UpdatedBy"] = entity.UpdatedBy.HasValue ? (object) entity.UpdatedBy  : System.DBNull.Value;

                    row["DeletedOn"] = entity.DeletedOn.HasValue ? (object) entity.DeletedOn  : System.DBNull.Value;

                    row["DeletedBy"] = entity.DeletedBy.HasValue ? (object) entity.DeletedBy  : System.DBNull.Value;

                dataTable.Rows.Add(row);
            }

            // send the data to the server
            bulkCopy.WriteToServer(dataTable);

            // update back the state
            foreach(Library.BLL.Employee entity in entities)
            {
                if (entity.EntityState != EntityState.Added)
                    continue;

                entity.AcceptChanges();
            }
        }
        /// <summary>
        /// Gets a page of rows from the DataSource.
        /// </summary>
        /// <param name="start">Row number at which to start reading.</param>
        /// <param name="pageLength">Number of rows to return.</param>
        /// <param name="count">Number of rows in the DataSource.</param>
        /// <param name="whereClause">Specifies the condition for the rows returned by a query (Name='John Doe', Name='John Doe' AND Id='1', Name='John Doe' OR Id='1').</param>
        /// <param name="orderBy">Specifies the sort criteria for the rows in the DataSource (Name ASC; BirthDay DESC, Name ASC);</param>
        /// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
        /// <remarks></remarks>
        /// <returns>Returns a typed collection of Library.BLL.BookImage objects.</returns>
        public override TList<BookImage> GetPaged(TransactionManager transactionManager, string whereClause, string orderBy, int start, int pageLength, out int count)
        {
            SqlDatabase database = new SqlDatabase(this._connectionString);
            DbCommand commandWrapper = StoredProcedureProvider.GetCommandWrapper(database, "dbo.BookImage_GetPaged", _useStoredProcedure);

            if (commandWrapper.CommandType == CommandType.Text
                && commandWrapper.CommandText != null)
            {
                commandWrapper.CommandText = commandWrapper.CommandText.Replace(SqlUtil.PAGE_INDEX, string.Concat(SqlUtil.PAGE_INDEX, Guid.NewGuid().ToString("N").Substring(0, 8)));
            }

            database.AddInParameter(commandWrapper, "@WhereClause", DbType.String, whereClause);
            database.AddInParameter(commandWrapper, "@OrderBy", DbType.String, orderBy);
            database.AddInParameter(commandWrapper, "@PageIndex", DbType.Int32, start);
            database.AddInParameter(commandWrapper, "@PageSize", DbType.Int32, pageLength);

            IDataReader reader = null;
            //Create Collection
            TList<BookImage> rows = new TList<BookImage>();

            try
            {
                //Provider Data Requesting Command Event
                OnDataRequesting(new CommandEventArgs(commandWrapper, "GetPaged", rows));

                if (transactionManager != null)
                {
                    reader = Utility.ExecuteReader(transactionManager, commandWrapper);
                }
                else
                {
                    reader = Utility.ExecuteReader(database, commandWrapper);
                }

                Fill(reader, rows, 0, int.MaxValue);
                count = rows.Count;

                if(reader.NextResult())
                {
                    if(reader.Read())
                    {
                        count = reader.GetInt32(0);
                    }
                }

                //Provider Data Requested Command Event
                OnDataRequested(new CommandEventArgs(commandWrapper, "GetPaged", rows));

            }
            catch(Exception)
            {
                throw;
            }
            finally
            {
                if (reader != null)
                    reader.Close();

                commandWrapper = null;
            }

            return rows;
        }
        /// <summary>
        /// 	Returns rows meeting the whereClause condition from the DataSource.
        /// </summary>
        /// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
        /// <param name="whereClause">Specifies the condition for the rows returned by a query (Name='John Doe', Name='John Doe' AND Id='1', Name='John Doe' OR Id='1').</param>
        /// <param name="start">Row number at which to start reading.</param>
        /// <param name="pageLength">Number of rows to return.</param>
        /// <param name="count">out. The number of rows that match this query.</param>
        /// <remarks>Operators must be capitalized (OR, AND).</remarks>
        /// <returns>Returns a typed collection of Library.BLL.Employee objects.</returns>
        public override TList<Employee> Find(TransactionManager transactionManager, string whereClause, int start, int pageLength, out int count)
        {
            count = -1;
            if (whereClause.IndexOf(";") > -1)
                return new TList<Employee>();

            SqlDatabase database = new SqlDatabase(this._connectionString);
            DbCommand commandWrapper = StoredProcedureProvider.GetCommandWrapper(database, "dbo.Employee_Find", _useStoredProcedure);

            bool searchUsingOR = false;
            if (whereClause.IndexOf(" OR ") > 0) // did they want to do "a=b OR c=d OR..."?
            searchUsingOR = true;

            database.AddInParameter(commandWrapper, "@SearchUsingOR", DbType.Boolean, searchUsingOR);

            database.AddInParameter(commandWrapper, "@ID", DbType.Int32, DBNull.Value);
            database.AddInParameter(commandWrapper, "@UserName", DbType.String, DBNull.Value);
            database.AddInParameter(commandWrapper, "@Password", DbType.String, DBNull.Value);
            database.AddInParameter(commandWrapper, "@Last_Login", DbType.DateTime, DBNull.Value);
            database.AddInParameter(commandWrapper, "@Last_Logout", DbType.DateTime, DBNull.Value);
            database.AddInParameter(commandWrapper, "@Is_Online", DbType.Boolean, DBNull.Value);
            database.AddInParameter(commandWrapper, "@Is_Active", DbType.Boolean, DBNull.Value);
            database.AddInParameter(commandWrapper, "@Is_Admin", DbType.Boolean, DBNull.Value);
            database.AddInParameter(commandWrapper, "@First_Name", DbType.String, DBNull.Value);
            database.AddInParameter(commandWrapper, "@Last_Name", DbType.String, DBNull.Value);
            database.AddInParameter(commandWrapper, "@Email", DbType.String, DBNull.Value);
            database.AddInParameter(commandWrapper, "@Country", DbType.String, DBNull.Value);
            database.AddInParameter(commandWrapper, "@City", DbType.String, DBNull.Value);
            database.AddInParameter(commandWrapper, "@Address", DbType.String, DBNull.Value);
            database.AddInParameter(commandWrapper, "@Mobile", DbType.String, DBNull.Value);
            database.AddInParameter(commandWrapper, "@Phone", DbType.String, DBNull.Value);
            database.AddInParameter(commandWrapper, "@Postion", DbType.String, DBNull.Value);
            database.AddInParameter(commandWrapper, "@Is_Deleted", DbType.Boolean, DBNull.Value);
            database.AddInParameter(commandWrapper, "@CreatedOn", DbType.DateTime, DBNull.Value);
            database.AddInParameter(commandWrapper, "@CreatedBy", DbType.Int32, DBNull.Value);
            database.AddInParameter(commandWrapper, "@UpdatedOn", DbType.DateTime, DBNull.Value);
            database.AddInParameter(commandWrapper, "@UpdatedBy", DbType.Int32, DBNull.Value);
            database.AddInParameter(commandWrapper, "@DeletedOn", DbType.DateTime, DBNull.Value);
            database.AddInParameter(commandWrapper, "@DeletedBy", DbType.Int32, DBNull.Value);

            // replace all instances of 'AND' and 'OR' because we already set searchUsingOR
            whereClause = whereClause.Replace(" AND ", "|").Replace(" OR ", "|") ;
            string[] clauses = whereClause.ToLower().Split('|');

            // Here's what's going on below: Find a field, then to get the value we
            // drop the field name from the front, trim spaces, drop the '=' sign,
            // trim more spaces, and drop any outer single quotes.
            // Now handles the case when two fields start off the same way - like "Friendly='Yes' AND Friend='john'"

            char[] equalSign = {'='};
            char[] singleQuote = {'\''};
               		foreach (string clause in clauses)
            {
                if (clause.Trim().StartsWith("id ") || clause.Trim().StartsWith("id="))
                {
                    database.SetParameterValue(commandWrapper, "@ID",
                        clause.Trim().Remove(0,2).Trim().TrimStart(equalSign).Trim().Trim(singleQuote));
                    continue;
                }
                if (clause.Trim().StartsWith("username ") || clause.Trim().StartsWith("username="******"@UserName",
                        clause.Trim().Remove(0,8).Trim().TrimStart(equalSign).Trim().Trim(singleQuote));
                    continue;
                }
                if (clause.Trim().StartsWith("password ") || clause.Trim().StartsWith("password="******"@Password",
                        clause.Trim().Remove(0,8).Trim().TrimStart(equalSign).Trim().Trim(singleQuote));
                    continue;
                }
                if (clause.Trim().StartsWith("last_login ") || clause.Trim().StartsWith("last_login="******"@Last_Login",
                        clause.Trim().Remove(0,10).Trim().TrimStart(equalSign).Trim().Trim(singleQuote));
                    continue;
                }
                if (clause.Trim().StartsWith("last_logout ") || clause.Trim().StartsWith("last_logout="))
                {
                    database.SetParameterValue(commandWrapper, "@Last_Logout",
                        clause.Trim().Remove(0,11).Trim().TrimStart(equalSign).Trim().Trim(singleQuote));
                    continue;
                }
                if (clause.Trim().StartsWith("is_online ") || clause.Trim().StartsWith("is_online="))
                {
                    database.SetParameterValue(commandWrapper, "@Is_Online",
                        clause.Trim().Remove(0,9).Trim().TrimStart(equalSign).Trim().Trim(singleQuote));
                    continue;
                }
                if (clause.Trim().StartsWith("is_active ") || clause.Trim().StartsWith("is_active="))
                {
                    database.SetParameterValue(commandWrapper, "@Is_Active",
                        clause.Trim().Remove(0,9).Trim().TrimStart(equalSign).Trim().Trim(singleQuote));
                    continue;
                }
                if (clause.Trim().StartsWith("is_admin ") || clause.Trim().StartsWith("is_admin="))
                {
                    database.SetParameterValue(commandWrapper, "@Is_Admin",
                        clause.Trim().Remove(0,8).Trim().TrimStart(equalSign).Trim().Trim(singleQuote));
                    continue;
                }
                if (clause.Trim().StartsWith("first_name ") || clause.Trim().StartsWith("first_name="))
                {
                    database.SetParameterValue(commandWrapper, "@First_Name",
                        clause.Trim().Remove(0,10).Trim().TrimStart(equalSign).Trim().Trim(singleQuote));
                    continue;
                }
                if (clause.Trim().StartsWith("last_name ") || clause.Trim().StartsWith("last_name="))
                {
                    database.SetParameterValue(commandWrapper, "@Last_Name",
                        clause.Trim().Remove(0,9).Trim().TrimStart(equalSign).Trim().Trim(singleQuote));
                    continue;
                }
                if (clause.Trim().StartsWith("email ") || clause.Trim().StartsWith("email="))
                {
                    database.SetParameterValue(commandWrapper, "@Email",
                        clause.Trim().Remove(0,5).Trim().TrimStart(equalSign).Trim().Trim(singleQuote));
                    continue;
                }
                if (clause.Trim().StartsWith("country ") || clause.Trim().StartsWith("country="))
                {
                    database.SetParameterValue(commandWrapper, "@Country",
                        clause.Trim().Remove(0,7).Trim().TrimStart(equalSign).Trim().Trim(singleQuote));
                    continue;
                }
                if (clause.Trim().StartsWith("city ") || clause.Trim().StartsWith("city="))
                {
                    database.SetParameterValue(commandWrapper, "@City",
                        clause.Trim().Remove(0,4).Trim().TrimStart(equalSign).Trim().Trim(singleQuote));
                    continue;
                }
                if (clause.Trim().StartsWith("address ") || clause.Trim().StartsWith("address="))
                {
                    database.SetParameterValue(commandWrapper, "@Address",
                        clause.Trim().Remove(0,7).Trim().TrimStart(equalSign).Trim().Trim(singleQuote));
                    continue;
                }
                if (clause.Trim().StartsWith("mobile ") || clause.Trim().StartsWith("mobile="))
                {
                    database.SetParameterValue(commandWrapper, "@Mobile",
                        clause.Trim().Remove(0,6).Trim().TrimStart(equalSign).Trim().Trim(singleQuote));
                    continue;
                }
                if (clause.Trim().StartsWith("phone ") || clause.Trim().StartsWith("phone="))
                {
                    database.SetParameterValue(commandWrapper, "@Phone",
                        clause.Trim().Remove(0,5).Trim().TrimStart(equalSign).Trim().Trim(singleQuote));
                    continue;
                }
                if (clause.Trim().StartsWith("postion ") || clause.Trim().StartsWith("postion="))
                {
                    database.SetParameterValue(commandWrapper, "@Postion",
                        clause.Trim().Remove(0,7).Trim().TrimStart(equalSign).Trim().Trim(singleQuote));
                    continue;
                }
                if (clause.Trim().StartsWith("is_deleted ") || clause.Trim().StartsWith("is_deleted="))
                {
                    database.SetParameterValue(commandWrapper, "@Is_Deleted",
                        clause.Trim().Remove(0,10).Trim().TrimStart(equalSign).Trim().Trim(singleQuote));
                    continue;
                }
                if (clause.Trim().StartsWith("createdon ") || clause.Trim().StartsWith("createdon="))
                {
                    database.SetParameterValue(commandWrapper, "@CreatedOn",
                        clause.Trim().Remove(0,9).Trim().TrimStart(equalSign).Trim().Trim(singleQuote));
                    continue;
                }
                if (clause.Trim().StartsWith("createdby ") || clause.Trim().StartsWith("createdby="))
                {
                    database.SetParameterValue(commandWrapper, "@CreatedBy",
                        clause.Trim().Remove(0,9).Trim().TrimStart(equalSign).Trim().Trim(singleQuote));
                    continue;
                }
                if (clause.Trim().StartsWith("updatedon ") || clause.Trim().StartsWith("updatedon="))
                {
                    database.SetParameterValue(commandWrapper, "@UpdatedOn",
                        clause.Trim().Remove(0,9).Trim().TrimStart(equalSign).Trim().Trim(singleQuote));
                    continue;
                }
                if (clause.Trim().StartsWith("updatedby ") || clause.Trim().StartsWith("updatedby="))
                {
                    database.SetParameterValue(commandWrapper, "@UpdatedBy",
                        clause.Trim().Remove(0,9).Trim().TrimStart(equalSign).Trim().Trim(singleQuote));
                    continue;
                }
                if (clause.Trim().StartsWith("deletedon ") || clause.Trim().StartsWith("deletedon="))
                {
                    database.SetParameterValue(commandWrapper, "@DeletedOn",
                        clause.Trim().Remove(0,9).Trim().TrimStart(equalSign).Trim().Trim(singleQuote));
                    continue;
                }
                if (clause.Trim().StartsWith("deletedby ") || clause.Trim().StartsWith("deletedby="))
                {
                    database.SetParameterValue(commandWrapper, "@DeletedBy",
                        clause.Trim().Remove(0,9).Trim().TrimStart(equalSign).Trim().Trim(singleQuote));
                    continue;
                }

                throw new ArgumentException("Unable to use this part of the where clause in this version of Find: " + clause);
            }

            IDataReader reader = null;
            //Create Collection
            TList<Employee> rows = new TList<Employee>();

            try
            {
                //Provider Data Requesting Command Event
                OnDataRequesting(new CommandEventArgs(commandWrapper, "Find", rows));

                if (transactionManager != null)
                {
                    reader = Utility.ExecuteReader(transactionManager, commandWrapper);
                }
                else
                {
                    reader = Utility.ExecuteReader(database, commandWrapper);
                }

                Fill(reader, rows, start, pageLength);

                if(reader.NextResult())
                {
                    if(reader.Read())
                    {
                        count = reader.GetInt32(0);
                    }
                }

                //Provider Data Requested Command Event
                OnDataRequested(new CommandEventArgs(commandWrapper, "Find", rows));
            }
            finally
            {
                if (reader != null)
                    reader.Close();

                commandWrapper = null;
            }
            return rows;
        }
        /// <summary>
        /// 	Update an existing row in the datasource.
        /// </summary>
        /// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
        /// <param name="entity">Library.BLL.BookImage object to update.</param>
        /// <remarks>
        ///		After updating the datasource, the Library.BLL.BookImage object will be updated
        /// 	to refelect any changes made by the datasource. (ie: identity or computed columns)
        /// </remarks>
        /// <returns>Returns true if operation is successful.</returns>
        /// <exception cref="System.Exception">The command could not be executed.</exception>
        /// <exception cref="System.Data.DataException">The <paramref name="transactionManager"/> is not open.</exception>
        /// <exception cref="System.Data.Common.DbException">The command could not be executed.</exception>
        public override bool Update(TransactionManager transactionManager, Library.BLL.BookImage entity)
        {
            SqlDatabase database = new SqlDatabase(this._connectionString);
            DbCommand commandWrapper = StoredProcedureProvider.GetCommandWrapper(database, "dbo.BookImage_Update", _useStoredProcedure);

            database.AddInParameter(commandWrapper, "@ID", DbType.Int32, entity.ID );
            database.AddInParameter(commandWrapper, "@Name", DbType.String, entity.Name );
            database.AddInParameter(commandWrapper, "@Format", DbType.String, entity.Format );
            database.AddInParameter(commandWrapper, "@Size", DbType.String, entity.Size );
            database.AddInParameter(commandWrapper, "@Link", DbType.String, entity.Link );
            database.AddInParameter(commandWrapper, "@IsAvailable", DbType.String, entity.IsAvailable );

            int results = 0;

            //Provider Data Requesting Command Event
            OnDataRequesting(new CommandEventArgs(commandWrapper, "Update", entity));

            if (transactionManager != null)
            {
                results = Utility.ExecuteNonQuery(transactionManager, commandWrapper);
            }
            else
            {
                results = Utility.ExecuteNonQuery(database,commandWrapper);
            }

            //Stop Tracking Now that it has been updated and persisted.
            if (DataRepository.Provider.EnableEntityTracking)
            {
                EntityManager.StopTracking(entity.EntityTrackingKey);
            }

            entity.AcceptChanges();

            //Provider Data Requested Command Event
            OnDataRequested(new CommandEventArgs(commandWrapper, "Update", entity));

            return Convert.ToBoolean(results);
        }
Esempio n. 27
0
 /// <summary>
 /// Executes the non query.
 /// </summary>
 /// <param name="transactionManager">The transaction manager.</param>
 /// <param name="storedProcedureName">Name of the stored procedure.</param>
 /// <param name="parameterValues">The parameter values.</param>
 /// <returns></returns>
 public override int ExecuteNonQuery(TransactionManager transactionManager, string storedProcedureName, params object[] parameterValues)
 {
     SqlDatabase database = new SqlDatabase(this._connectionString);
     return database.ExecuteNonQuery(transactionManager.TransactionObject, storedProcedureName, parameterValues);
 }