private void ReloadLocales(SqlConnection connection) { _localesByName.Clear(); _localesById.Clear(); var command = new SqlCommand(String.Format( "select {0}, {1} from {2}", IdColumn, NameColumn, _table ), connection); using (var result = command.ExecuteReader()) { if (result.HasRows) { while (result.Read()) { var locale = new DBLocale(result.GetInt32(0), result.GetString(1)); _localesByName.Add(locale.Name, locale); _localesById.Add(locale.Id, locale); } } } }
public bool Equals(DBLocale other) { if (ReferenceEquals(null, other)) return false; if (ReferenceEquals(this, other)) return true; return base.Equals(other) && other.Id == Id; }
public DBLocale Insert(String name, Connector connector) { var connection = connector.Connection; if(connection.State != ConnectionState.Open) connection.Open(); var command = new SqlCommand(String.Format( "insert into {0}({1}) values(@name); select IDENT_CURRENT('{0}')", _table, NameColumn ), connection ); command.Parameters.Add(new SqlParameter("name", SqlDbType.VarChar) { Value = name }); var newLocale = new DBLocale(Int32.Parse(command.ExecuteScalar().ToString()), name); _localesByName[newLocale.Name] = newLocale; _localesById[newLocale.Id] = newLocale; return newLocale; }