public virtual async Task <bool> DeleteModelAsync <T>(T model) where T : class { var type = typeof(T); string key = AttrAssistant.GetKey(type); if (!key.IsNullOrEmpty()) { object primaryKeyUniqueValue = RefProperty.GetPropertyValue(model, key); return(await DeleteAsync <T>(primaryKeyUniqueValue)); } return(false); }
public virtual async Task <bool> UpdateModelAsync <T>(T model) where T : class { var arrProperty = typeof(T).GetProperties(); var builderSQL = new StringBuilder(); var lstParams = new List <DbParameter>(); foreach (var property in arrProperty) { //关键字key 和 不属于表的属性NotMapped 不更新 if (AttrAssistant.IsKey(property) || AttrAssistant.IsNotMapped(property)) { continue; } //没有提供数据的字段也不处理 object obj = property.GetValue(model, null); if (obj == null) { continue; } builderSQL.AppendFormat("{0}=@{0} , ", property.Name); lstParams.Add(MakeParam("@" + property.Name, obj)); } builderSQL.Remove(builderSQL.Length - 2, 2); string key = AttrAssistant.GetKey(typeof(T)); if (!key.IsNullOrEmpty()) { //主键值 object primaryKeyUniqueValue = RefProperty.GetPropertyValue(model, key); builderSQL.AppendFormat(" where {0}=@primaryKeyUniqueValue ", key); lstParams.Add(MakeParam("@primaryKeyUniqueValue", primaryKeyUniqueValue)); } return(await ExecSQLAsync(" update " + AttrAssistant.GetTableName(typeof(T)) + " set " + builderSQL.ToString(), lstParams.ToArray())); }
public PersonViewModel2(Person person) { Vorname = new RefProperty <string>(() => person.Vorname, v => person.Vorname = v); }