public static int Delete <T>(this DbAccessor db, object objIdParameters) { var tableMapping = new TableMapping(typeof(T)); ISqlBuilder sqlBuilder = new DefaultSqlBuilder(tableMapping); #region 处理参数为基础类型,即直接为主键的值 if (objIdParameters.GetType() == typeof(string) || objIdParameters.GetType().GetTypeInfo().IsPrimitive) { var dicParam = new Dictionary <string, object>(); var keyColumns = tableMapping.GetKeyColumns(); if (keyColumns.Count == 0) { throw new Exceptions.EntityException("实体没有设置主键!"); } string keyColumnName = keyColumns[0].ColumnName; dicParam.Add(keyColumnName, objIdParameters); objIdParameters = dicParam; } #endregion return(db.ExecuteNonQuery(sqlBuilder.BuildDelete(), objIdParameters)); }
public void TableMapping() { TableMapping table = new TableMapping(typeof(SysProduct)); Console.WriteLine(table.TableName); foreach (var col in table.Columns) { Console.WriteLine(col.ColumnName + " " + col.IsPrimaryKey); } DefaultSqlBuilder sqlb = new DefaultSqlBuilder(table); Console.WriteLine(sqlb.BuildDelete()); Console.WriteLine(sqlb.BuildInsert()); Console.WriteLine(sqlb.BuildUpdate()); }
public static int Delete(this DbAccessor db, object objEntity) { ISqlBuilder sqlBuilder = new DefaultSqlBuilder(new TableMapping(objEntity.GetType())); return(db.ExecuteNonQuery(sqlBuilder.BuildDelete(), objEntity)); }