private IEnumerable Execute(BuiltQuery builtQuery) { if (EntityHelpers.IsConstant(builtQuery.EntityType)) { var constantWrapType = builtQuery.EntityType.BaseType; if (constantWrapType == null) { throw new InvalidOperationException("assertion failure"); } var constantWrap = (Constant)FormatterServices.GetUninitializedObject(builtQuery.EntityType); var constants = ComHelpers.GetProperty(globalContext.ComObject(), "Константы"); var constant = ComHelpers.GetProperty(constants, builtQuery.EntityType.Name); var value = ComHelpers.Invoke(constant, "Получить"); constantWrap.ЗначениеНетипизированное = comObjectMapper.MapFrom1C(value, constantWrapType.GetGenericArguments()[0]); yield return(constantWrap); yield break; } var queryText = builtQuery.QueryText; var parameters = builtQuery.Parameters; parametersConverter.ConvertParametersTo1C(parameters); var hasReference = ConfigurationName.Get(builtQuery.EntityType).HasReference; var queryResult = globalContext.Execute(queryText, parameters); if (hasReference || builtQuery.Projection != null) { var projection = builtQuery.Projection != null ? ProjectionMapperFactory.GetMapper(builtQuery.Projection, comObjectMapper) : null; var selection = queryResult.Select(); while (selection.Next()) { if (projection != null) { yield return(projection(selection.ComObject)); } else if (builtQuery.IsCount) { yield return(comObjectMapper.MapFrom1C(selection["src_Count"], typeof(int))); } else { yield return(comObjectMapper.MapFrom1C(selection["Ссылка"], builtQuery.EntityType)); } } } else { var valueTable = queryResult.Unload(); foreach (var r in valueTable) { yield return(comObjectMapper.MapFrom1C(r.ComObject(), builtQuery.EntityType)); } } }
internal void PrepareToSave(Abstract1CEntity owner, List <Abstract1CEntity> entitiesToSave) { if (observedValues != null) { foreach (var item in observedValues) { if (Changed != null && Changed.ContainsKey(item.Key)) { continue; } var value = item.Value; var entity = value.value as Abstract1CEntity; if (entity != null) { entity.Controller.PrepareToSave(entity, entitiesToSave); continue; } var list = value.value as IList; if (list != null) { foreach (Abstract1CEntity e in list) { e.Controller.PrepareToSave(e, entitiesToSave); } var syncList = SyncList.Compare(value.originalList, list); if (syncList.Commands.Count > 0) { MarkAsChanged(item.Key, syncList); } } } observedValues = null; } if (!EntityHelpers.IsTableSection(owner.GetType()) && IsDirty) { entitiesToSave.Add(owner); } }