public EndpointInfo GetOrCreate(string endpoint, IJetTransaction jetTransaction) { EndpointInfo resultInfo = null; OleDbCommand oleDbCommand = jetTransaction.CreateOleCommand(); oleDbCommand.CommandText = string.Format("SELECT [ID] FROM {0} WHERE [Endpoint]=@Endpoint;", _endpointTable.TableName); oleDbCommand.Parameters.AddWithValue("@Endpoint", endpoint); OleDbDataReader reader = oleDbCommand.ExecuteReader(CommandBehavior.SingleRow); if (!reader.HasRows) { resultInfo = this.Add(endpoint, jetTransaction); } else { reader.Read(); int id = Convert.ToInt32(reader["ID"]); resultInfo = new EndpointInfo(id, endpoint); } return resultInfo; }
private EndpointInfo Add(string endpoint, IJetTransaction jetTransaction) { EndpointInfo resultInfo = null; OleDbCommand oleDbCommand = jetTransaction.CreateOleCommand(); oleDbCommand.CommandText = string.Format("INSERT INTO [{0}] ([Endpoint]) VALUES (@Endpoint);", _endpointTable.TableName); oleDbCommand.Parameters.AddWithValue("@Endpoint", endpoint); oleDbCommand.ExecuteNonQuery(); oleDbCommand.Parameters.Clear(); oleDbCommand.CommandText = string.Format("SELECT @@IDENTITY FROM [{0}];", _endpointTable.TableName); oleDbCommand.CommandType = CommandType.Text; int newId = (int)oleDbCommand.ExecuteScalar(); resultInfo = new EndpointInfo(newId, endpoint); return resultInfo; }