public List<Relationship> Read() {
            var relationships = new List<Relationship>();

            foreach (var r in _elements) {
                Entity leftEntity;
                if (!_process.Entities.TryFind(r.LeftEntity, out leftEntity)) {
                    throw new TransformalizeException(_process.Logger, r.LeftEntity, "Can't find left entity {0}.", r.LeftEntity);
                }

                Entity rightEntity;
                if (!_process.Entities.TryFind(r.RightEntity, out rightEntity)) {
                    throw new TransformalizeException(_process.Logger, r.RightEntity, "Can't find right entity {0}.", r.RightEntity);
                }

                var join = GetJoins(r, leftEntity, rightEntity);
                var relationship = new Relationship {
                    LeftEntity = leftEntity,
                    RightEntity = rightEntity,
                    Index = r.Index,
                    Join = join
                };

                relationships.Add(relationship);
            }
            return relationships;
        }
 public EntityJoinOperation(Process process, Relationship rel)
     : base(process) {
     _rel = rel;
     var rightFields = new HashSet<string>(rel.RightEntity.OutputFields().Aliases());
     rightFields.ExceptWith(rel.LeftEntity.OutputFields().Aliases());
     _fields = rightFields.ToArray();
 }
        public string CreateRelationshipIndexStatement(Relationship relationship) {
            var pattern = _process.OutputConnection.IndexInclude ?
                "CREATE INDEX {0} ON {1}.{2}({3}) INCLUDE(TflBatchId,TflKey);" :
                "CREATE INDEX {0} ON {1}.{2}({3},TflBatchId,TflKey);";

            var joinFields = relationship.Join.Select(j => j.LeftField.Alias).ToArray();
            var indexName = string.Format(
                "IX_{0}_{1}",
                _process.MasterEntity.OutputName(),
                string.Join("_", joinFields)
            ).Left(128).Trim('_');
            return string.Format(
                pattern,
                _process.OutputConnection.Enclose(indexName),
                _process.OutputConnection.Enclose(string.IsNullOrEmpty(_process.MasterEntity.Schema) ? _process.OutputConnection.DefaultSchema : _process.MasterEntity.Schema),
                _process.OutputConnection.Enclose(_process.MasterEntity.OutputName()),
                string.Join(",", joinFields.Select(_process.OutputConnection.Enclose))
            );
        }
 private bool JoinAndPrimaryKeyAreSame(Relationship relationship) {
     return relationship.Join.Select(j => j.LeftField.Alias)
         .SequenceEqual(_process.MasterEntity.PrimaryKey.Aliases());
 }