/// <summary>
        /// 处理关联的实体集合。
        /// </summary>
        /// <param name="queryable"></param>
        /// <param name="entity"></param>
        /// <param name="entitySet"></param>
        /// <param name="property"></param>
        private void HandleRelationEntitySet(IQueryable queryable, IEntity entity, IEntitySet entitySet, IProperty property)
        {
            var added    = entitySet.GetAttachedList();
            var modified = entitySet.GetModifiedList();
            var deleted  = entitySet.GetDetachedList();

            //处理删除的
            if (deleted.Count() > 0)
            {
                queryable.BatchOperate(deleted, queryable.CreateDeleteExpression(true));
            }

            //处理修改的
            if (modified.Count() > 0)
            {
                if (entitySet.AllowBatchUpdate)
                {
                    queryable.BatchOperate(modified, queryable.CreateUpdateExpression());
                }
                else
                {
                    foreach (var e in modified)
                    {
                        queryable.UpdateEntity(e);
                        e.SetState(EntityState.Unchanged);
                        HandleRelationProperties(e);
                    }
                }
            }

            //处理新增的
            if (added.Count() > 0)
            {
                var relation = RelationshipUnity.GetRelationship(property);
                added.ForEach(e =>
                {
                    foreach (var key in relation.Keys)
                    {
                        var value = entity.GetValue(key.ThisProperty);
                        e.SetValue(key.OtherProperty, value);
                    }
                });

                if (entitySet.AllowBatchInsert)
                {
                    queryable.BatchOperate(added, queryable.CreateInsertExpression());
                }
                else
                {
                    foreach (var e in added)
                    {
                        queryable.CreateEntity(e);
                        e.SetState(EntityState.Unchanged);
                        HandleRelationProperties(e);
                    }
                }
            }

            entitySet.Reset();
        }
Esempio n. 2
0
 private static void FillDataTableRows(DataTable table, IEntitySet extendList, IList <IProperty> properties, bool hasPrmKey)
 {
     FillDataTableRows(table, extendList.GetAttachedList(), properties, hasPrmKey, EntityState.Attached);
     FillDataTableRows(table, extendList.GetModifiedList(), properties, hasPrmKey, EntityState.Modified);
     FillDataTableRows(table, extendList.GetDetachedList(), properties, hasPrmKey, EntityState.Detached);
     extendList.Reset();
 }
Esempio n. 3
0
        /// <summary>
        /// 处理关联的实体集合。
        /// </summary>
        /// <param name="queryable"></param>
        /// <param name="entity"></param>
        /// <param name="entitySet"></param>
        /// <param name="property"></param>
        private async Task HandleEntitySetPropertyAsync(IQueryable queryable, IEntity entity, IEntitySet entitySet, IProperty property, CancellationToken cancellationToken = default)
        {
            var added    = entitySet.GetAttachedList();
            var modified = entitySet.GetModifiedList();
            var deleted  = entitySet.GetDetachedList();

            //处理删除的
            if (deleted.Count() > 0)
            {
                await queryable.BatchOperateAsync(deleted, queryable.CreateDeleteExpression(true), cancellationToken);
            }

            //处理修改的
            if (modified.Count() > 0)
            {
                if (entitySet.AllowBatchUpdate)
                {
                    await queryable.BatchOperateAsync(modified, queryable.CreateUpdateExpression(), cancellationToken);
                }
                else
                {
                    foreach (var e in modified)
                    {
                        await queryable.UpdateEntityAsync(e, cancellationToken);

                        e.SetState(EntityState.Unchanged);
                        await HandleRelationPropertiesAsync(e, cancellationToken);
                    }
                }
            }

            //处理新增的
            if (added.Count() > 0)
            {
                var relation = RelationshipUnity.GetRelationship(property);
                added.ForEach(e =>
                {
                    foreach (var key in relation.Keys)
                    {
                        var value = entity.GetValue(key.ThisProperty);
                        e.SetValue(key.OtherProperty, value);
                    }
                });

                if (entitySet.AllowBatchInsert)
                {
                    await queryable.BatchOperateAsync(added, queryable.CreateInsertExpression(), cancellationToken);
                }
                else
                {
                    foreach (var e in added)
                    {
                        await queryable.CreateEntityAsync(e, cancellationToken);

                        e.SetState(EntityState.Unchanged);
                        await HandleRelationPropertiesAsync(e, cancellationToken);
                    }
                }
            }

            entitySet.Reset();
        }