Exemplo n.º 1
0
        /// <summary>
        /// Given a stream of relationships, returns a stream where applicable relationships are duplicated so that their
        /// reverse alias also appears in the output stream.
        /// Caution: remember to invert the from/to types, and the cardinality, as applicable.
        /// </summary>
        /// <param name="types"></param>
        /// <returns></returns>
        IEnumerable <EffectiveRelationship> EffectiveRelationships(IEnumerable <Entity> relationships)
        {
            foreach (var type in relationships)
            {
                bool isSingleEnum = false;
                var  card         = _schemaManager.GetCardinality(type);
                if (card == Aliases.ManyToOne)
                {
                    var relToType = _schemaManager.GetRelationshipToType(type);
                    var entType   = _schemaManager.GetEntityType(relToType).Alias;
                    isSingleEnum = entType == Aliases.EnumType;
                }
                var et = new EffectiveRelationship()
                {
                    Type = type, Alias = type.Alias, IsSingleEnum = isSingleEnum
                };
                yield return(et);

                if (type.ReverseAlias != null)
                {
                    var rev = new EffectiveRelationship()
                    {
                        Type = type, Alias = type.ReverseAlias, IsReverseAlias = true, IsSingleEnum = false
                    };
                    yield return(rev);
                }
            }
        }