/// <summary> /// 根据<see cref="SqlSearchKeyAttribute"/>将数据库相应行中<see cref="SqlBindingAttribute"/>绑定的属性更新。 /// </summary> /// <param name="obj"></param> /// <param name="binding"></param> public static void Update(this ISqlObject obj, string binding) { //获取成员列表。 NameValueList vs = new NameValueList(); foreach (var property in obj.GetType().GetProperties()) { if (property.CanWrite && property.CanRead && property.TryGetSqlElementName(out string name) && property.SqlBindingExists(binding)) { //加密。 vs.Add(name, GetSqlValue(property.GetValue(obj), property.IsSqlEncrypt())); } } //生成命令语句。 string cmd = $"update {obj.Table} set " + string.Join(',', vs.Map((m) => $"{m.Name}={m.Value}")) + " " + obj.GetWhereExpression(); obj.SqlProvider.Execute(cmd); }