Exemple #1
0
        /// <summary>
        /// Get collection of entities using provided filters.
        /// </summary>
        /// <param name="sourceEntityName">Name of entity for loading.</param>
        /// <param name="columnList">List of columns to be loaded.</param>
        /// <param name="filterCollection">Dictionary, containing column name as a key and value for filtering as a value.</param>
        /// <returns><see cref="EntityCollection"/>.</returns>
        public virtual EntityCollection GetItems(string sourceEntityName, IEnumerable <string> columnList,
                                                 EntityCollectionMappingHandlerFilterGroup filterCollection = null)
        {
            var esq = new EntitySchemaQuery(UserConnection.EntitySchemaManager, sourceEntityName);

            esq.PrimaryQueryColumn.IsAlwaysSelect = true;
            foreach (var columnName in columnList)
            {
                var name = esq.AddColumn(columnName);
            }
            if (filterCollection != null)
            {
                var filterGroup = new EntitySchemaQueryFilterCollection(esq, filterCollection.LogicalOperation);
                foreach (var filterItem in filterCollection.Filters)
                {
                    var innerFilterGroup = new EntitySchemaQueryFilterCollection(esq, filterItem.LogicalOperation);
                    foreach (var filterItemValue in filterItem.Values)
                    {
                        var filterComparisonType = filterItem.ComparisonType;
                        if (filterItemValue == null)
                        {
                            filterComparisonType = FilterComparisonType.IsNull;
                        }
                        innerFilterGroup.Add(esq.CreateFilterWithParameters(filterComparisonType, filterItem.ColumnPath, filterItemValue));
                    }
                    filterGroup.Add(innerFilterGroup);
                }
                esq.Filters.Add(filterGroup);
            }
            return(esq.GetEntityCollection(UserConnection));
        }
Exemple #2
0
        /// <summary>
        /// Delete records by provided filters.
        /// </summary>
        /// <param name="entityName">Name of entity to be deleted.</param>
        /// <param name="filterCollection">Dictionary, containing column name as a key and value for filtering as a value.</param>
        public virtual void DeleteItems(string entityName, EntityCollectionMappingHandlerFilterGroup filterCollection)
        {
            var entityCollection = GetItems(entityName, new string[] { }, filterCollection);

            foreach (var item in entityCollection)
            {
                var entitySchema = UserConnection.EntitySchemaManager.GetInstanceByName(entityName);
                var entity       = entitySchema.CreateEntity(UserConnection);
                entity.FetchFromDB(item.GetTypedColumnValue <Guid>("Id"));
                entity.Delete();
            }
        }
Exemple #3
0
        /// <summary>
        /// Copy records by provided filters.
        /// </summary>
        /// <param name="entityName">Name of entity to be copied.</param>
        /// <param name="columnList">List of columns to copy.</param>
        /// <param name="columnMapping">Dictionary, containing column name in source collection as a key and column name in target entity as a value.</param>
        /// <param name="filterCollection">Filters for entity.</param>
        /// <param name="defaultValues">Default values.</param>
        /// <returns><see cref=" Dictionary<Guid, Guid>"/>.</returns>
        public virtual Dictionary <Guid, Guid> CopyItems(string entitySchemaName, IEnumerable <string> columnList,
                                                         EntityCollectionMappingHandlerFilterGroup filterCollection = null, Dictionary <string, object> defaultValues = null)
        {
            var entityCollection = GetItems(entitySchemaName, columnList, filterCollection);

            if (!entityCollection.Any())
            {
                return(new Dictionary <Guid, Guid>());
            }
            SetDefaultValues(entityCollection, defaultValues);
            var columnMapping = GetColumnMappingFromColumnList(entitySchemaName, columnList);

            return(SaveItems(entityCollection, entitySchemaName, columnMapping, false));
        }