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