/// <summary> /// Updates /// </summary> /// <param name="entity"></param> public void Update(BaseEntity entity) { SqlStringGenerator stringgenerator = new SqlStringGenerator(this.MapInfoSession); UpdateQuery updatequery = stringgenerator.GenerateUpdateQuery(entity, this.Name); updatequery.ExecuteNonQuery(); }
/// <summary> /// Generates a <see cref="UpdateQuery"/> for the supplied entity, using the data in each of the entities /// properties with /// </summary> /// <param name="entity"></param> /// <param name="tableName"></param> /// <returns></returns> public UpdateQuery GenerateUpdateQuery(BaseEntity entity, string tableName) { Guard.AgainstNull(entity, "entity"); IEnumerable <PropertyInfo> props = GetVaildProperties(entity); StringBuilder updatestring = new StringBuilder("UPDATE {0} SET ".FormatWith(entity.Table.Name)); string wherestring = " WHERE RowID = {0}".FormatWith(entity.RowId);; UpdateQuery query = new UpdateQuery(this.mapinfo, entity.Table.Name); ColumnWithData col; foreach (PropertyInfo property in props) { string name = property.Name; object columnvalue = property.GetValue(entity, null); MapInfoColumnAttribute attribute = (MapInfoColumnAttribute)property.GetCustomAttributes(typeof(MapInfoColumnAttribute), true).FirstOrDefault(); ColumnType columnType = attribute.Type; object resultvalue = null; resultvalue = GetConvertedValue(columnType, columnvalue); updatestring.AppendFormat("{0} = {1},", name, resultvalue); } return(new UpdateQuery(this.mapinfo, updatestring.ToString().TrimEnd(',') + wherestring)); }