/// <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)); }
public Query GenerateUpdateQuery(BaseEntity entity) { Guard.AgainstNull(entity, "entity"); List <PropertyInfo> props = (from pro in entity.GetType().GetProperties() where Attribute.IsDefined(pro, typeof(MapInfoColumnAttribute)) select pro).ToList(); UpdateQuery query = new UpdateQuery(this.mapinfo, entity.Table.Name); ColumnWithData col; foreach (PropertyInfo property in props) { col = new ColumnWithData(); col.Name = property.Name; string name = property.Name; object value = property.GetValue(entity, null); col.Value = value; MapInfoColumnAttribute attribute = (MapInfoColumnAttribute)property.GetCustomAttributes(typeof(MapInfoColumnAttribute), true).FirstOrDefault(); col.Type = attribute.Type; query.ColumnsAndData.Add(col); } col = new ColumnWithData(); col.Name = "rowid"; col.Type = ColumnType.INTEGER; col.Value = entity.RowId; query.ColumnsAndData.Add(col); return(query); }