/// <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 HearbalKartDB.Entities.States 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<HearbalKartDB.Entities.States> 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 = "States";
			
			DataTable dataTable = new DataTable();
			DataColumn col0 = dataTable.Columns.Add("ID", typeof(System.Int32));
			col0.AllowDBNull = false;		
			DataColumn col1 = dataTable.Columns.Add("CountryID", typeof(System.Int32));
			col1.AllowDBNull = true;		
			DataColumn col2 = dataTable.Columns.Add("Name", typeof(System.String));
			col2.AllowDBNull = true;		
			DataColumn col3 = dataTable.Columns.Add("Pin", typeof(System.Int64));
			col3.AllowDBNull = true;		
			DataColumn col4 = dataTable.Columns.Add("IsActive", typeof(System.Boolean));
			col4.AllowDBNull = true;		
			DataColumn col5 = dataTable.Columns.Add("CreatedDate", typeof(System.DateTime));
			col5.AllowDBNull = true;		
			DataColumn col6 = dataTable.Columns.Add("ModifiedDate", typeof(System.DateTime));
			col6.AllowDBNull = true;		
			DataColumn col7 = dataTable.Columns.Add("DeletedDate", typeof(System.DateTime));
			col7.AllowDBNull = true;		
			DataColumn col8 = dataTable.Columns.Add("PinCode", typeof(System.String));
			col8.AllowDBNull = true;		
			
			bulkCopy.ColumnMappings.Add("ID", "ID");
			bulkCopy.ColumnMappings.Add("CountryID", "CountryID");
			bulkCopy.ColumnMappings.Add("Name", "Name");
			bulkCopy.ColumnMappings.Add("Pin", "Pin");
			bulkCopy.ColumnMappings.Add("IsActive", "IsActive");
			bulkCopy.ColumnMappings.Add("CreatedDate", "CreatedDate");
			bulkCopy.ColumnMappings.Add("ModifiedDate", "ModifiedDate");
			bulkCopy.ColumnMappings.Add("DeletedDate", "DeletedDate");
			bulkCopy.ColumnMappings.Add("PinCode", "PinCode");
			
			foreach(HearbalKartDB.Entities.States entity in entities)
			{
				if (entity.EntityState != EntityState.Added)
					continue;
					
				DataRow row = dataTable.NewRow();
				
					row["ID"] = entity.Id;
							
				
					row["CountryID"] = entity.CountryId.HasValue ? (object) entity.CountryId  : System.DBNull.Value;
							
				
					row["Name"] = entity.Name;
							
				
					row["Pin"] = entity.Pin.HasValue ? (object) entity.Pin  : System.DBNull.Value;
							
				
					row["IsActive"] = entity.IsActive.HasValue ? (object) entity.IsActive  : System.DBNull.Value;
							
				
					row["CreatedDate"] = entity.CreatedDate.HasValue ? (object) entity.CreatedDate  : System.DBNull.Value;
							
				
					row["ModifiedDate"] = entity.ModifiedDate.HasValue ? (object) entity.ModifiedDate  : System.DBNull.Value;
							
				
					row["DeletedDate"] = entity.DeletedDate.HasValue ? (object) entity.DeletedDate  : System.DBNull.Value;
							
				
					row["PinCode"] = entity.PinCode;
							
				
				dataTable.Rows.Add(row);
			}		
			
			// send the data to the server		
			bulkCopy.WriteToServer(dataTable);		
			
			// update back the state
			foreach(HearbalKartDB.Entities.States entity in entities)
			{
				if (entity.EntityState != EntityState.Added)
					continue;
			
				entity.AcceptChanges();
			}
		}
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_States_Countries key.
		///		FK_States_Countries 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="_countryId"></param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of HearbalKartDB.Entities.States 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<States> GetByCountryId(TransactionManager transactionManager, System.Int32? _countryId, int start, int pageLength, out int count)
		{
			SqlDatabase database = new SqlDatabase(this._connectionString);
			DbCommand commandWrapper = StoredProcedureProvider.GetCommandWrapper(database, "dbo.States_GetByCountryId", _useStoredProcedure);
			
				database.AddInParameter(commandWrapper, "@CountryId", DbType.Int32, _countryId);
			
			IDataReader reader = null;
			TList<States> rows = new TList<States>();
			try
			{
				//Provider Data Requesting Command Event
				OnDataRequesting(new CommandEventArgs(commandWrapper, "GetByCountryId", 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, "GetByCountryId", rows)); 
			}
			finally
			{
				if (reader != null) 
					reader.Close();
					
				commandWrapper = null;
			}
			return rows;
		}	
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_States 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="HearbalKartDB.Entities.States"/> 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 HearbalKartDB.Entities.States 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.States_GetById", _useStoredProcedure);
			
				database.AddInParameter(commandWrapper, "@Id", DbType.Int32, _id);
			
			IDataReader reader = null;
			TList<States> tmp = new TList<States>();
			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>
		/// 	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 HearbalKartDB.Entities.States objects.</returns>
		public override TList<States> 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.States_Find_Dynamic", typeof(StatesColumn), 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<States> rows = new TList<States>();
			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;
		}
		}//end getall
		
		#endregion
				
		#region GetPaged Methods
				
		/// <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 HearbalKartDB.Entities.States objects.</returns>
		public override TList<States> 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.States_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<States> rows = new TList<States>();
			
			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>
		/// 	Inserts a HearbalKartDB.Entities.ProdTable object into the datasource using a transaction.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="entity">HearbalKartDB.Entities.ProdTable object to insert.</param>
		/// <remarks>
		///		After inserting into the datasource, the HearbalKartDB.Entities.ProdTable 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, HearbalKartDB.Entities.ProdTable entity)
		{
			SqlDatabase database = new SqlDatabase(this._connectionString);
			DbCommand commandWrapper = StoredProcedureProvider.GetCommandWrapper(database, "dbo.ProdTable_Insert", _useStoredProcedure);
			
			database.AddOutParameter(commandWrapper, "@Id", DbType.Int32, 4);
			database.AddInParameter(commandWrapper, "@ItemId", DbType.Int32, (entity.ItemId.HasValue ? (object) entity.ItemId  : System.DBNull.Value));
			database.AddInParameter(commandWrapper, "@CategoryId", DbType.Int32, (entity.CategoryId.HasValue ? (object) entity.CategoryId  : System.DBNull.Value));
			database.AddInParameter(commandWrapper, "@CompanyId", DbType.Int32, (entity.CompanyId.HasValue ? (object) entity.CompanyId  : System.DBNull.Value));
			database.AddInParameter(commandWrapper, "@TypeId", DbType.Int32, (entity.TypeId.HasValue ? (object) entity.TypeId  : System.DBNull.Value));
			database.AddInParameter(commandWrapper, "@SupplementId", DbType.Int32, (entity.SupplementId.HasValue ? (object) entity.SupplementId  : System.DBNull.Value));
			database.AddInParameter(commandWrapper, "@MedicineForId", DbType.Int32, (entity.MedicineForId.HasValue ? (object) entity.MedicineForId  : System.DBNull.Value));
			database.AddInParameter(commandWrapper, "@PurchaseId", DbType.Int32, (entity.PurchaseId.HasValue ? (object) entity.PurchaseId  : System.DBNull.Value));
			database.AddInParameter(commandWrapper, "@SellId", DbType.Int32, (entity.SellId.HasValue ? (object) entity.SellId  : System.DBNull.Value));
			database.AddInParameter(commandWrapper, "@OfferId", DbType.Int32, (entity.OfferId.HasValue ? (object) entity.OfferId  : System.DBNull.Value));
			database.AddInParameter(commandWrapper, "@IsActive", DbType.Boolean, (entity.IsActive.HasValue ? (object) entity.IsActive  : System.DBNull.Value));
			database.AddInParameter(commandWrapper, "@CreatedDate", DbType.DateTime, (entity.CreatedDate.HasValue ? (object) entity.CreatedDate  : System.DBNull.Value));
			database.AddInParameter(commandWrapper, "@ModifiedDate", DbType.DateTime, (entity.ModifiedDate.HasValue ? (object) entity.ModifiedDate  : System.DBNull.Value));
			database.AddInParameter(commandWrapper, "@DeletedDate", DbType.DateTime, (entity.DeletedDate.HasValue ? (object) entity.DeletedDate  : System.DBNull.Value));
            database.AddInParameter(commandWrapper, "@ImageUrl", DbType.String, entity.ImageUrl );
			
			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);
		}	
		}//end Delete
		#endregion

		#region Find Functions

		#region Parsed Find Methods
		/// <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 HearbalKartDB.Entities.States objects.</returns>
		public override TList<States> Find(TransactionManager transactionManager, string whereClause, int start, int pageLength, out int count)
		{
			count = -1;
			if (whereClause.IndexOf(";") > -1)
				return new TList<States>();
	
			SqlDatabase database = new SqlDatabase(this._connectionString);
			DbCommand commandWrapper = StoredProcedureProvider.GetCommandWrapper(database, "dbo.States_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, "@CountryId", DbType.Int32, DBNull.Value);
		database.AddInParameter(commandWrapper, "@Name", DbType.String, DBNull.Value);
		database.AddInParameter(commandWrapper, "@Pin", DbType.Int64, DBNull.Value);
		database.AddInParameter(commandWrapper, "@IsActive", DbType.Boolean, DBNull.Value);
		database.AddInParameter(commandWrapper, "@CreatedDate", DbType.DateTime, DBNull.Value);
		database.AddInParameter(commandWrapper, "@ModifiedDate", DbType.DateTime, DBNull.Value);
		database.AddInParameter(commandWrapper, "@DeletedDate", DbType.DateTime, DBNull.Value);
		database.AddInParameter(commandWrapper, "@PinCode", 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("countryid ") || clause.Trim().StartsWith("countryid="))
				{
					database.SetParameterValue(commandWrapper, "@CountryId", 
						clause.Trim().Remove(0,9).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("pin ") || clause.Trim().StartsWith("pin="))
				{
					database.SetParameterValue(commandWrapper, "@Pin", 
						clause.Trim().Remove(0,3).Trim().TrimStart(equalSign).Trim().Trim(singleQuote));
					continue;
				}
				if (clause.Trim().StartsWith("isactive ") || clause.Trim().StartsWith("isactive="))
				{
					database.SetParameterValue(commandWrapper, "@IsActive", 
						clause.Trim().Remove(0,8).Trim().TrimStart(equalSign).Trim().Trim(singleQuote));
					continue;
				}
				if (clause.Trim().StartsWith("createddate ") || clause.Trim().StartsWith("createddate="))
				{
					database.SetParameterValue(commandWrapper, "@CreatedDate", 
						clause.Trim().Remove(0,11).Trim().TrimStart(equalSign).Trim().Trim(singleQuote));
					continue;
				}
				if (clause.Trim().StartsWith("modifieddate ") || clause.Trim().StartsWith("modifieddate="))
				{
					database.SetParameterValue(commandWrapper, "@ModifiedDate", 
						clause.Trim().Remove(0,12).Trim().TrimStart(equalSign).Trim().Trim(singleQuote));
					continue;
				}
				if (clause.Trim().StartsWith("deleteddate ") || clause.Trim().StartsWith("deleteddate="))
				{
					database.SetParameterValue(commandWrapper, "@DeletedDate", 
						clause.Trim().Remove(0,11).Trim().TrimStart(equalSign).Trim().Trim(singleQuote));
					continue;
				}
				if (clause.Trim().StartsWith("pincode ") || clause.Trim().StartsWith("pincode="))
				{
					database.SetParameterValue(commandWrapper, "@PinCode", 
						clause.Trim().Remove(0,7).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<States> rows = new TList<States>();
	
				
			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;
		}
Ejemplo n.º 8
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>
		/// 	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 HearbalKartDB.Entities.Cities 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<Cities> GetAll(TransactionManager transactionManager, int start, int pageLength, out int count)
		{
			SqlDatabase database = new SqlDatabase(this._connectionString);
			DbCommand commandWrapper = StoredProcedureProvider.GetCommandWrapper(database, "dbo.Cities_Get_List", _useStoredProcedure);
			
			IDataReader reader = null;
		
			//Create Collection
			TList<Cities> rows = new TList<Cities>();
			
			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;
		}//end getall
Ejemplo n.º 10
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);	
		}
Ejemplo 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);	
		}
Ejemplo n.º 12
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);				
		}
Ejemplo n.º 13
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);	
		}
Ejemplo n.º 14
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);	
		}
		/// <summary>
		/// 	Inserts a HearbalKartDB.Entities.States object into the datasource using a transaction.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="entity">HearbalKartDB.Entities.States object to insert.</param>
		/// <remarks>
		///		After inserting into the datasource, the HearbalKartDB.Entities.States 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, HearbalKartDB.Entities.States entity)
		{
			SqlDatabase database = new SqlDatabase(this._connectionString);
			DbCommand commandWrapper = StoredProcedureProvider.GetCommandWrapper(database, "dbo.States_Insert", _useStoredProcedure);
			
			database.AddOutParameter(commandWrapper, "@Id", DbType.Int32, 4);
			database.AddInParameter(commandWrapper, "@CountryId", DbType.Int32, (entity.CountryId.HasValue ? (object) entity.CountryId  : System.DBNull.Value));
            database.AddInParameter(commandWrapper, "@Name", DbType.String, entity.Name );
			database.AddInParameter(commandWrapper, "@Pin", DbType.Int64, (entity.Pin.HasValue ? (object) entity.Pin  : System.DBNull.Value));
			database.AddInParameter(commandWrapper, "@IsActive", DbType.Boolean, (entity.IsActive.HasValue ? (object) entity.IsActive  : System.DBNull.Value));
			database.AddInParameter(commandWrapper, "@CreatedDate", DbType.DateTime, (entity.CreatedDate.HasValue ? (object) entity.CreatedDate  : System.DBNull.Value));
			database.AddInParameter(commandWrapper, "@ModifiedDate", DbType.DateTime, (entity.ModifiedDate.HasValue ? (object) entity.ModifiedDate  : System.DBNull.Value));
			database.AddInParameter(commandWrapper, "@DeletedDate", DbType.DateTime, (entity.DeletedDate.HasValue ? (object) entity.DeletedDate  : System.DBNull.Value));
            database.AddInParameter(commandWrapper, "@PinCode", DbType.String, entity.PinCode );
			
			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.States_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(States)
					,_id);
                EntityManager.StopTracking(entityKey);
                
			}
			
			//Provider Data Requested Command Event
			OnDataRequested(new CommandEventArgs(commandWrapper, "Delete")); 

			commandWrapper = null;
			
			return Convert.ToBoolean(results);
		}//end Delete
		/// <summary>
		/// 	Update an existing row in the datasource.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="entity">HearbalKartDB.Entities.States object to update.</param>
		/// <remarks>
		///		After updating the datasource, the HearbalKartDB.Entities.States 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, HearbalKartDB.Entities.States entity)
		{
			SqlDatabase database = new SqlDatabase(this._connectionString);
			DbCommand commandWrapper = StoredProcedureProvider.GetCommandWrapper(database, "dbo.States_Update", _useStoredProcedure);
			
            database.AddInParameter(commandWrapper, "@Id", DbType.Int32, entity.Id );
			database.AddInParameter(commandWrapper, "@CountryId", DbType.Int32, (entity.CountryId.HasValue ? (object) entity.CountryId : System.DBNull.Value) );
            database.AddInParameter(commandWrapper, "@Name", DbType.String, entity.Name );
			database.AddInParameter(commandWrapper, "@Pin", DbType.Int64, (entity.Pin.HasValue ? (object) entity.Pin : System.DBNull.Value) );
			database.AddInParameter(commandWrapper, "@IsActive", DbType.Boolean, (entity.IsActive.HasValue ? (object) entity.IsActive : System.DBNull.Value) );
			database.AddInParameter(commandWrapper, "@CreatedDate", DbType.DateTime, (entity.CreatedDate.HasValue ? (object) entity.CreatedDate : System.DBNull.Value) );
			database.AddInParameter(commandWrapper, "@ModifiedDate", DbType.DateTime, (entity.ModifiedDate.HasValue ? (object) entity.ModifiedDate : System.DBNull.Value) );
			database.AddInParameter(commandWrapper, "@DeletedDate", DbType.DateTime, (entity.DeletedDate.HasValue ? (object) entity.DeletedDate : System.DBNull.Value) );
            database.AddInParameter(commandWrapper, "@PinCode", DbType.String, entity.PinCode );
			
			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 HearbalKartDB.Entities.ProdTable 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<HearbalKartDB.Entities.ProdTable> 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 = "ProdTable";
			
			DataTable dataTable = new DataTable();
			DataColumn col0 = dataTable.Columns.Add("ID", typeof(System.Int32));
			col0.AllowDBNull = false;		
			DataColumn col1 = dataTable.Columns.Add("ItemID", typeof(System.Int32));
			col1.AllowDBNull = true;		
			DataColumn col2 = dataTable.Columns.Add("CategoryID", typeof(System.Int32));
			col2.AllowDBNull = true;		
			DataColumn col3 = dataTable.Columns.Add("CompanyID", typeof(System.Int32));
			col3.AllowDBNull = true;		
			DataColumn col4 = dataTable.Columns.Add("TypeID", typeof(System.Int32));
			col4.AllowDBNull = true;		
			DataColumn col5 = dataTable.Columns.Add("SupplementID", typeof(System.Int32));
			col5.AllowDBNull = true;		
			DataColumn col6 = dataTable.Columns.Add("MedicineForID", typeof(System.Int32));
			col6.AllowDBNull = true;		
			DataColumn col7 = dataTable.Columns.Add("PurchaseID", typeof(System.Int32));
			col7.AllowDBNull = true;		
			DataColumn col8 = dataTable.Columns.Add("SellID", typeof(System.Int32));
			col8.AllowDBNull = true;		
			DataColumn col9 = dataTable.Columns.Add("OfferID", typeof(System.Int32));
			col9.AllowDBNull = true;		
			DataColumn col10 = dataTable.Columns.Add("IsActive", typeof(System.Boolean));
			col10.AllowDBNull = true;		
			DataColumn col11 = dataTable.Columns.Add("CreatedDate", typeof(System.DateTime));
			col11.AllowDBNull = true;		
			DataColumn col12 = dataTable.Columns.Add("ModifiedDate", typeof(System.DateTime));
			col12.AllowDBNull = true;		
			DataColumn col13 = dataTable.Columns.Add("DeletedDate", typeof(System.DateTime));
			col13.AllowDBNull = true;		
			DataColumn col14 = dataTable.Columns.Add("ImageUrl", typeof(System.String));
			col14.AllowDBNull = true;		
			
			bulkCopy.ColumnMappings.Add("ID", "ID");
			bulkCopy.ColumnMappings.Add("ItemID", "ItemID");
			bulkCopy.ColumnMappings.Add("CategoryID", "CategoryID");
			bulkCopy.ColumnMappings.Add("CompanyID", "CompanyID");
			bulkCopy.ColumnMappings.Add("TypeID", "TypeID");
			bulkCopy.ColumnMappings.Add("SupplementID", "SupplementID");
			bulkCopy.ColumnMappings.Add("MedicineForID", "MedicineForID");
			bulkCopy.ColumnMappings.Add("PurchaseID", "PurchaseID");
			bulkCopy.ColumnMappings.Add("SellID", "SellID");
			bulkCopy.ColumnMappings.Add("OfferID", "OfferID");
			bulkCopy.ColumnMappings.Add("IsActive", "IsActive");
			bulkCopy.ColumnMappings.Add("CreatedDate", "CreatedDate");
			bulkCopy.ColumnMappings.Add("ModifiedDate", "ModifiedDate");
			bulkCopy.ColumnMappings.Add("DeletedDate", "DeletedDate");
			bulkCopy.ColumnMappings.Add("ImageUrl", "ImageUrl");
			
			foreach(HearbalKartDB.Entities.ProdTable entity in entities)
			{
				if (entity.EntityState != EntityState.Added)
					continue;
					
				DataRow row = dataTable.NewRow();
				
					row["ID"] = entity.Id;
							
				
					row["ItemID"] = entity.ItemId.HasValue ? (object) entity.ItemId  : System.DBNull.Value;
							
				
					row["CategoryID"] = entity.CategoryId.HasValue ? (object) entity.CategoryId  : System.DBNull.Value;
							
				
					row["CompanyID"] = entity.CompanyId.HasValue ? (object) entity.CompanyId  : System.DBNull.Value;
							
				
					row["TypeID"] = entity.TypeId.HasValue ? (object) entity.TypeId  : System.DBNull.Value;
							
				
					row["SupplementID"] = entity.SupplementId.HasValue ? (object) entity.SupplementId  : System.DBNull.Value;
							
				
					row["MedicineForID"] = entity.MedicineForId.HasValue ? (object) entity.MedicineForId  : System.DBNull.Value;
							
				
					row["PurchaseID"] = entity.PurchaseId.HasValue ? (object) entity.PurchaseId  : System.DBNull.Value;
							
				
					row["SellID"] = entity.SellId.HasValue ? (object) entity.SellId  : System.DBNull.Value;
							
				
					row["OfferID"] = entity.OfferId.HasValue ? (object) entity.OfferId  : System.DBNull.Value;
							
				
					row["IsActive"] = entity.IsActive.HasValue ? (object) entity.IsActive  : System.DBNull.Value;
							
				
					row["CreatedDate"] = entity.CreatedDate.HasValue ? (object) entity.CreatedDate  : System.DBNull.Value;
							
				
					row["ModifiedDate"] = entity.ModifiedDate.HasValue ? (object) entity.ModifiedDate  : System.DBNull.Value;
							
				
					row["DeletedDate"] = entity.DeletedDate.HasValue ? (object) entity.DeletedDate  : System.DBNull.Value;
							
				
					row["ImageUrl"] = entity.ImageUrl;
							
				
				dataTable.Rows.Add(row);
			}		
			
			// send the data to the server		
			bulkCopy.WriteToServer(dataTable);		
			
			// update back the state
			foreach(HearbalKartDB.Entities.ProdTable entity in entities)
			{
				if (entity.EntityState != EntityState.Added)
					continue;
			
				entity.AcceptChanges();
			}
		}