/// <summary> /// 获取数据层(用作运行SQL) /// </summary> /// <returns></returns> public DataAccessSetBase GetDAL() { if (_dal == null) { EntityInfoHandle handle = EntityInfoManager.GetEntityHandle(typeof(T)); _dal = new DataAccessSetBase(handle); _dal.Oper = StaticConnection.GetStaticOperate(handle.DBInfo); } return(_dal); }
/// <summary> /// 获取基础数据层 /// </summary> /// <returns></returns> private DataAccessSetBase GetBaseDataAccess() { if (_dal == null) { EntityInfoHandle handle = EntityInfoManager.GetEntityHandle(CH.GetRealType(this)); _dal = new DataAccessSetBase(handle); _dal.Oper = StaticConnection.GetStaticOperate(handle.DBInfo); } return(_dal); }
/// <summary> /// 更新实体 /// </summary> /// <param name="lstValue">强制设置值</param> /// <param name="optimisticConcurrency">是否并发控制</param> /// <returns></returns> public virtual int Update(ValueSetList lstValue, bool optimisticConcurrency) { DataAccessSetBase dal = GetBaseDataAccess(); foreach (EntityPropertyInfo epPk in dal.EntityInfo.PrimaryProperty) { object id = epPk.GetValue(this); if (DefaultType.IsDefaultValue(id)) { throw new Exception("主键:" + epPk.PropertyName + "的值不能为空"); } } return(dal.Update(this, null, lstValue, optimisticConcurrency)); }
/// <summary> /// 并发删除 /// </summary> /// <param name="optimisticConcurrency">是否并发控制</param> /// <returns></returns> public virtual int Delete(bool optimisticConcurrency) { DataAccessSetBase dal = GetBaseDataAccess(); ScopeList lstScope = new ScopeList(); foreach (EntityPropertyInfo pInfo in dal.EntityInfo.PrimaryProperty) { object id = pInfo.GetValue(this); if (DefaultType.IsDefaultValue(id)) { throw new Exception("主键:" + pInfo.PropertyName + "的值不能为空"); } lstScope.AddEqual(pInfo.PropertyName, id); } return(dal.Delete(this, lstScope, optimisticConcurrency)); }
/// <summary> /// 保存实体并填充ID /// </summary> /// <param name="fillPrimaryKey">是否填充实体</param> /// <returns></returns> public virtual int Insert(ValueSetList setList, bool fillPrimaryKey) { DataAccessSetBase dal = GetBaseDataAccess(); return(dal.DoInsert(this, setList, fillPrimaryKey)); }