示例#1
0
        private static IEnumerable <T> GenerateDirectRelationships <T>(string value) where T : DirectRelationship
        {
            List <T> rels = new List <T>();

            KeyValuePair <string, string[]>[] segments = GetSegments(value);
            string entity = segments[0].Key;

            string[] properties = segments[0].Value;

            for (int i = 0; i < segments.Length - 1; i++)
            {
                string   relatedEntity = segments[i + 1].Key;
                string[] nextProps     = segments[i + 1].Value;

                string[] relatedProperties = new string[properties.Length];
                Array.Copy(nextProps, relatedProperties, properties.Length);
                string[] remain = new string[nextProps.Length - properties.Length];
                Array.Copy(nextProps, properties.Length, remain, 0, remain.Length);

                DirectRelationship rel;
                if (typeof(T) == typeof(ManyToOneDirectRelationship))
                {
                    rel = new ManyToOneDirectRelationship(entity, relatedEntity, properties, relatedProperties);
                }
                else if (typeof(T) == typeof(OneToManyDirectRelationship))
                {
                    rel = new OneToManyDirectRelationship(entity, relatedEntity, properties, relatedProperties);
                }
                else if (typeof(T) == typeof(OneToOneDirectRelationship))
                {
                    rel = new OneToOneDirectRelationship(entity, relatedEntity, properties, relatedProperties);
                }
                else
                {
                    rel = new DirectRelationship(entity, relatedEntity, properties, relatedProperties);
                }
                rels.Add(rel as T);

                entity     = relatedEntity;
                properties = remain;
            }

            return(rels);
        }
示例#2
0
 public OneToManyDirectRelationship(ManyToOneDirectRelationship relationship)
     : base(relationship.RelatedEntity, relationship.Entity, relationship.RelatedProperties.ToArray(), relationship.Properties.ToArray())
 {
 }