public static bool DbInsert(this TArea entity, DbSession session) { var query = IORMProvider.GetDbQueryBuilder(session); InsertBuilder builder = new InsertBuilder(); builder.ComponentInsert.Add(new ComponentValueOfInsert(TAreaProperties.AreaId, entity.AreaId)); if (entity.AreaName == null) { throw new NotImplementedException("缺少必填的参数项值, 参数项: " + nameof(entity.AreaName)); } builder.ComponentInsert.Add(new ComponentValueOfInsert(TAreaProperties.AreaName, entity.AreaName)); builder.ComponentInsert.Add(new ComponentValueOfInsert(TAreaProperties.AreaLevel, entity.AreaLevel)); builder.ComponentInsert.Add(new ComponentValueOfInsert(TAreaProperties.AreaType, entity.AreaType)); if (entity.Description == null) { throw new NotImplementedException("缺少必填的参数项值, 参数项: " + nameof(entity.Description)); } builder.ComponentInsert.Add(new ComponentValueOfInsert(TAreaProperties.Description, entity.Description)); if (entity.DescriptionEx == null) { throw new NotImplementedException("缺少必填的参数项值, 参数项: " + nameof(entity.DescriptionEx)); } builder.ComponentInsert.Add(new ComponentValueOfInsert(TAreaProperties.DescriptionEx, entity.DescriptionEx)); query.InsertBuilders.Add(builder); return(IORMProvider.GetQueryOperator(session).Insert <TArea>(session, query)); }
public static TArea DbSelect(this TArea entity, DbSession session, params PDMDbProperty[] fields) { var query = IORMProvider.GetDbQueryBuilder(session); SelectBuilder builder = new SelectBuilder(); if (fields.Count() == 0) { builder.ComponentSelect.Add(TAreaProperties.AreaId); builder.ComponentSelect.Add(TAreaProperties.AreaName); builder.ComponentSelect.Add(TAreaProperties.AreaLevel); builder.ComponentSelect.Add(TAreaProperties.AreaType); builder.ComponentSelect.Add(TAreaProperties.Description); builder.ComponentSelect.Add(TAreaProperties.DescriptionEx); } else { builder.ComponentSelect.Add(TAreaProperties.AreaId); foreach (var field in fields) { builder.ComponentSelect.Add(field); } } builder.ComponentWhere.Add(new ComponentValueOfWhere(TAreaProperties.AreaId, entity.AreaId, LocateType.Equal)); query.SelectBuilders.Add(builder); return(IORMProvider.GetQueryOperator(session).Select <TArea>(session, query)); }
public static void DbLoad(this TArea entity, DbSession session, params PDMDbProperty[] fields) { var result = entity.DbSelect(session, fields); if (fields.Contains(TAreaProperties.AreaName)) { entity.AreaName = result.AreaName; } if (fields.Contains(TAreaProperties.AreaLevel)) { entity.AreaLevel = result.AreaLevel; } if (fields.Contains(TAreaProperties.AreaType)) { entity.AreaType = result.AreaType; } if (fields.Contains(TAreaProperties.Description)) { entity.Description = result.Description; } if (fields.Contains(TAreaProperties.DescriptionEx)) { entity.DescriptionEx = result.DescriptionEx; } }
public static bool DbDelete(this TArea entity, DbSession session) { var query = IORMProvider.GetDbQueryBuilder(session); query.DeleteBuilder.ComponentWhere.Add(new ComponentValueOfWhere(TAreaProperties.AreaId, entity.AreaId, LocateType.Equal)); return(IORMProvider.GetQueryOperator(session).Delete <TArea>(session, query)); }
public static bool DbUpdate(this TArea entity, DbSession session, params PDMDbProperty[] fields) { var query = IORMProvider.GetDbQueryBuilder(session); UpdateBuilder builder = new UpdateBuilder(); builder.ComponentWhere.Add(new ComponentValueOfWhere(TAreaProperties.AreaId, entity.AreaId, LocateType.Equal)); if (fields == null || fields.Length == 0) { builder.ComponentSet.Add(new ComponentValueOfSet(TAreaProperties.AreaId, entity.AreaId)); builder.ComponentSet.Add(new ComponentValueOfSet(TAreaProperties.AreaName, entity.AreaName)); builder.ComponentSet.Add(new ComponentValueOfSet(TAreaProperties.AreaLevel, entity.AreaLevel)); builder.ComponentSet.Add(new ComponentValueOfSet(TAreaProperties.AreaType, entity.AreaType)); builder.ComponentSet.Add(new ComponentValueOfSet(TAreaProperties.Description, entity.Description)); builder.ComponentSet.Add(new ComponentValueOfSet(TAreaProperties.DescriptionEx, entity.DescriptionEx)); } else { if (fields.Contains(TAreaProperties.AreaName)) { builder.ComponentSet.Add(new ComponentValueOfSet(TAreaProperties.AreaName, entity.AreaName)); } if (fields.Contains(TAreaProperties.AreaLevel)) { builder.ComponentSet.Add(new ComponentValueOfSet(TAreaProperties.AreaLevel, entity.AreaLevel)); } if (fields.Contains(TAreaProperties.AreaType)) { builder.ComponentSet.Add(new ComponentValueOfSet(TAreaProperties.AreaType, entity.AreaType)); } if (fields.Contains(TAreaProperties.Description)) { builder.ComponentSet.Add(new ComponentValueOfSet(TAreaProperties.Description, entity.Description)); } if (fields.Contains(TAreaProperties.DescriptionEx)) { builder.ComponentSet.Add(new ComponentValueOfSet(TAreaProperties.DescriptionEx, entity.DescriptionEx)); } } query.UpdateBuilders.Add(builder); return(IORMProvider.GetQueryOperator(session).Update <TArea>(session, query)); }