public virtual void Update(TEntity entity) { var map = CacheManger.GetTableMap(typeof(TEntity)); QueueSql.Sql = new StringBuilder(); var strWhereSql = Visit.Where(QueueSql.ExpWhere); var strAssemble = Visit.Assign(entity); // 主键如果有值,则需要 去掉主键的赋值、并且加上主键的条件 if (map.GetModelInfo().Key != null) { var value = map.GetModelInfo().Key.GetValue(entity, null); if (value != null) { if (!string.IsNullOrWhiteSpace(strWhereSql)) { strWhereSql += " AND "; } strWhereSql += string.Format("{0} = {1}", map.IndexName, value); } } if (!string.IsNullOrWhiteSpace(strWhereSql)) { strWhereSql = "WHERE " + strWhereSql; } QueueSql.Sql.AppendFormat("UPDATE {0} SET {1} {2}", QueueManger.DbProvider.KeywordAegis(QueueSql.Name), strAssemble, strWhereSql); }
public virtual Queue Update <TEntity>(TEntity entity) where TEntity : class, new() { Queue.Sql = new StringBuilder(); var strWhereSql = Visit.Where(Queue.ExpWhere); var strAssemble = Visit.Assign(entity); var readCondition = Visit.ReadCondition(entity); Check.NotEmpty(strAssemble, "更新操作时,当前实体没有要更新的字段。" + typeof(TEntity)); // 主键如果有值、或者设置成只读条件,则自动转成条件 if (!string.IsNullOrWhiteSpace(readCondition)) { strWhereSql += string.IsNullOrWhiteSpace(strWhereSql) ? readCondition : " AND " + readCondition; } if (!string.IsNullOrWhiteSpace(strWhereSql)) { strWhereSql = "WHERE " + strWhereSql; } Queue.Sql.AppendFormat("UPDATE {0} SET {1} {2}", QueueManger.DbProvider.KeywordAegis(Queue.Name), strAssemble, strWhereSql); return(Queue); }