private IEnumerable <RuleEntityConnBindingModel> GetEntityConnBindingCollection()
        {
            List <RuleEntityConnBindingModel> result = new List <RuleEntityConnBindingModel>();
            var esq = new EntitySchemaQuery(_userConnection.EntitySchemaManager, "EntityConnBinding");

            esq.PrimaryQueryColumn.IsAlwaysSelect = true;
            var parentIdColumn   = esq.AddColumn("EntityConnectionParentId");
            var childIdColumn    = esq.AddColumn("EntityConnectionChildId");
            var entityCollection = esq.GetEntityCollection(_userConnection);

            foreach (var item in entityCollection)
            {
                EntityConnectionModel targetEntityConnection = GetEntityConnection(item.GetTypedColumnValue <Guid>(parentIdColumn.ValueQueryAlias));
                EntityConnectionModel sourceEntityConnection = GetEntityConnection(item.GetTypedColumnValue <Guid>(childIdColumn.ValueQueryAlias));
                if (targetEntityConnection != null && sourceEntityConnection != null)
                {
                    RuleEntityConnBindingModel model = new RuleEntityConnBindingModel();
                    model.TargetEntitySchemaUId       = targetEntityConnection.SysEntitySchemaUId;
                    model.TargetEntitySchemaColumnUId = targetEntityConnection.ColumnUId;
                    model.SourceEntitySchemaUId       = sourceEntityConnection.SysEntitySchemaUId;
                    model.SourceEntitySchemaColumnUId = sourceEntityConnection.ColumnUId;
                    result.Add(model);
                }
            }
            return(result);
        }
        private EntityConnectionModel GetEntityConnection(Guid id)
        {
            EntityConnectionModel result = new EntityConnectionModel();
            var esq = new EntitySchemaQuery(_userConnection.EntitySchemaManager, "EntityConnection");

            esq.PrimaryQueryColumn.IsAlwaysSelect = true;
            var sysEntitySchemaUIdColumn = esq.AddColumn("SysEntitySchemaUId");
            var columnUIdColumn          = esq.AddColumn("ColumnUId");

            esq.Filters.Add(esq.CreateFilterWithParameters(
                                FilterComparisonType.Equal,
                                esq.PrimaryQueryColumn.Name,
                                id
                                ));
            var entityCollection = esq.GetEntityCollection(_userConnection);

            if (entityCollection.Count > 0)
            {
                result.SysEntitySchemaUId = entityCollection[0].GetTypedColumnValue <Guid>(sysEntitySchemaUIdColumn.ValueQueryAlias);
                result.ColumnUId          = entityCollection[0].GetTypedColumnValue <Guid>(columnUIdColumn.ValueQueryAlias);
                return(result);
            }
            else
            {
                return(null);
            }
        }