private ParameterSource CreateParameterSourceOfFindOrderDetailByCriterion(int orderId) { Criterion orderCriterion = new Criterion { IsKeyParam = true, ParamName = "@OrderID", ParamType = DbType.Int32, ParamValue = orderId }; ParameterSource parameterSource = new ParameterSource(); parameterSource.AddCriterion(orderCriterion); return(parameterSource); }
private ParameterSource CreateParameterSourceOfFindCategoryById(int categoryId) { Criterion categoryCriterion = new Criterion { IsKeyParam = true, ParamName = "@CategoryID", ParamType = DbType.Int32, ParamValue = categoryId }; ParameterSource parameterSource = new ParameterSource(); parameterSource.AddCriterion(categoryCriterion); return(parameterSource); }
private ParameterSource CreateParameterSourceOfFindProductById(int productId) { Criterion productCriterion = new Criterion { IsKeyParam = true, ParamName = "@ProductID", ParamType = DbType.Int32, ParamValue = productId }; ParameterSource parameterSource = new ParameterSource(); parameterSource.AddCriterion(productCriterion); return(parameterSource); }
protected DomainObject AbstractFindSingleWithParameterSource(Type type, ParameterSource parameterSource) { // Check identity map. DomainObject result = identityMap.GetDomainObject(type, parameterSource.UniqueId); if (result != null) { return(result); } // Identity map not hit, do query. using (DbConnection connection = providerFactory.CreateConnection()) { connection.ConnectionString = DbSettings.ConnectionString; connection.Open(); DbCommand command = providerFactory.CreateCommand(); command.Connection = connection; command.CommandText = FindSingleStatement(); // Find single, implement by derived class. foreach (Criterion criterion in parameterSource.GetAllCriteria()) { DbParameter parameter = providerFactory.CreateParameter(); parameter.ParameterName = criterion.ParamName; parameter.DbType = criterion.ParamType; parameter.Value = criterion.ParamValue; command.Parameters.Add(parameter); } DbDataReader reader = command.ExecuteReader(); reader.Read(); int AffectedRows = reader.RecordsAffected; Console.WriteLine("Find() RowsAffected: {0}", AffectedRows); DomainObject domainObject = Load(type, parameterSource.UniqueId, (IDataRecord)reader); return(domainObject); } }
public OrderDetail FindOrderDetailById(int orderId, int productId) { ParameterSource parameterSource = CreateParameterSourceOfFindOrderDetailById(orderId, productId); return((OrderDetail)AbstractFindSingleWithParameterSource(typeof(OrderDetail), parameterSource)); }
public Category FindCategoryById(int categoryId) { ParameterSource parameterSource = CreateParameterSourceOfFindCategoryById(categoryId); return((Category)AbstractFindSingleWithParameterSource(typeof(Category), parameterSource)); }
public Product FindProductById(int productId) { ParameterSource parameterSource = CreateParameterSourceOfFindProductById(productId); return((Product)AbstractFindSingleWithParameterSource(typeof(Product), parameterSource)); }
protected IList <DomainObject> AbstractFindManyWithParameterSource(Type type, ParameterSource parameterSource) { using (DbConnection connection = providerFactory.CreateConnection()) { connection.ConnectionString = DbSettings.ConnectionString; connection.Open(); DbCommand command = providerFactory.CreateCommand(); command.Connection = connection; command.CommandText = FindManyStatement(); // Find many, implement by derived class. foreach (Criterion criterion in parameterSource.GetAllCriteria()) { DbParameter parameter = providerFactory.CreateParameter(); parameter.ParameterName = criterion.ParamName; parameter.DbType = criterion.ParamType; parameter.Value = criterion.ParamValue; command.Parameters.Add(parameter); } DbDataReader reader = command.ExecuteReader(); int AffectedRows = reader.RecordsAffected; Console.WriteLine("Find() RowsAffected: {0}", AffectedRows); IList <DomainObject> results = new List <DomainObject>(); while (reader.Read()) { string UniqueId = GetUniqueId((IDataRecord)reader); DomainObject item = Load(type, UniqueId, (IDataRecord)reader); results.Add(item); } return(results); } }