private void DataPortal_Fetch(CategoryCriteria criteria) { bool cancel = false; OnFetching(criteria, ref cancel); if (cancel) { return; } using (var connection = new SqlConnection(ADOHelper.ConnectionString)) { connection.Open(); using (var command = new SqlCommand("[dbo].[CSLA_Category_Select]", connection)) { command.CommandType = CommandType.StoredProcedure; command.Parameters.AddRange(ADOHelper.SqlParameters(criteria.StateBag)); command.Parameters.AddWithValue("@p_NameHasValue", criteria.NameHasValue); command.Parameters.AddWithValue("@p_DescnHasValue", criteria.DescriptionHasValue); using (var reader = new SafeDataReader(command.ExecuteReader())) { if (reader.Read()) { Map(reader); } else { throw new Exception(String.Format("The record was not found in 'dbo.Category' using the following criteria: {0}.", criteria)); } } } } OnFetched(); }
protected override void DataPortal_Execute() { string commandText = String.Format("SELECT COUNT(1) FROM {0} {1}", Criteria.TableFullName, ADOHelper.BuildWhereStatement(Criteria.StateBag)); using (var connection = new SqlConnection(ADOHelper.ConnectionString)) { connection.Open(); using (var command = new SqlCommand(commandText, connection)) { command.Parameters.AddRange(ADOHelper.SqlParameters(Criteria.StateBag)); Result = (int)command.ExecuteScalar() > 0; } } }
private void DataPortal_Fetch(CategoryCriteria criteria) { IsReadOnly = false; bool cancel = false; OnFetching(criteria, ref cancel); if (cancel) { return; } RaiseListChangedEvents = false; // Fetch Child objects. using (var connection = new SqlConnection(ADOHelper.ConnectionString)) { connection.Open(); using (var command = new SqlCommand("[dbo].[CSLA_Category_Select]", connection)) { command.CommandType = CommandType.StoredProcedure; command.Parameters.AddRange(ADOHelper.SqlParameters(criteria.StateBag)); command.Parameters.AddWithValue("@p_NameHasValue", criteria.NameHasValue); command.Parameters.AddWithValue("@p_DescnHasValue", criteria.DescriptionHasValue); using (var reader = new SafeDataReader(command.ExecuteReader())) { if (reader.Read()) { do { this.Add(PetShop.Tests.Collections.ReadOnlyRoot.CategoryInfo.GetCategoryInfo(reader)); } while(reader.Read()); } } } } RaiseListChangedEvents = true; OnFetched(); IsReadOnly = true; }