public int?GetOrderIfExistsFor(AggregateConfiguration configuration) { if (configuration.Repository != this) { if (((CatalogueRepository)configuration.Repository).ConnectionString != CatalogueRepository.ConnectionString) { throw new NotSupportedException("AggregateConfiguration is from a different repository than this with a different connection string"); } } using (var con = CatalogueRepository.GetConnection()) { DbCommand cmd = DatabaseCommandHelper.GetCommand("SELECT [Order] FROM CohortAggregateContainer_AggregateConfiguration WHERE AggregateConfiguration_ID = @AggregateConfiguration_ID", con.Connection, con.Transaction); cmd.Parameters.Add(DatabaseCommandHelper.GetParameter("@AggregateConfiguration_ID", cmd)); cmd.Parameters["@AggregateConfiguration_ID"].Value = configuration.ID; return(CatalogueRepository.ObjectToNullableInt(cmd.ExecuteScalar())); } }