/// <summary> /// 提供将提供的实体添加到数据库的方法 /// </summary> /// <param name="item">增加的实体</param> /// <param name="connectionString">自定应的连接字符串</param> /// <param name="dataBaseType">自定应数据库类型</param> /// <param name="frameMappingType">所应用的映射类型</param> /// <returns>返回影响的行数</returns> internal static int Add(object item, string connectionString, FrameData.DataBaseType dataBaseType, FrameMappingType frameMappingType) { Dictionary <string, object> columnDic = FrameData.FrameDataBase.GetColumnDic(item, frameMappingType); string insertSql = FrameGenerateSql.GenerateInsertSql(item.GetType().ToString(), columnDic, dataBaseType); return(FrameData.FrameDataBase.ExecuteNonQuery(connectionString, insertSql, System.Data.CommandType.Text, FrameDataBase.GetParameters(columnDic, dataBaseType), dataBaseType)); }
/// <summary> /// 提供删除传入实体的方法 /// 条件为主键相同,该实体必须有且仅有一个字段被特性 [PrimaryKeyAttribute] 标识为主键 /// </summary> /// <param name="item">要删除的 实体</param> /// <param name="connectionString">自定义的 连接字符串</param> /// <param name="dataBaseType">自定义 数据库类型</param> /// <returns>返回影响的 行数</returns> internal static int Delete(object item, string connectionString, FrameData.DataBaseType dataBaseType) { Dictionary <string, object> primaryKeyDic = FrameData.FrameDataBase.GetColumnDicByUserAttribute <CoreAttribute.PrimaryKeyAttribute>(item, null); if (primaryKeyDic.Count > 1) { throw new Exception(FrameWork.Core.Resources.Exceptions.FrameCHExceptionResource.__FrameEntityPrimaryKeyToMary); } if (primaryKeyDic.Count < 1) { throw new Exception(FrameWork.Core.Resources.Exceptions.FrameCHExceptionResource.__FrameEntityPrimaryKeyNull); } string deleteSql = FrameGenerateSql.GenerateDeleteSql(item.GetType().ToString(), primaryKeyDic.First().Key, dataBaseType); return(FrameData.FrameDataBase.ExecuteNonQuery(connectionString, deleteSql, System.Data.CommandType.Text, FrameDataBase.GetParameters(primaryKeyDic, dataBaseType), dataBaseType)); }