public void Populate()
        {
            Merges = new List <MergeDescriptor.Merge>();
            var statementParser = new MergeStatementParser();

            var parser = new ScriptParser(statementParser, _path);

            parser.Parse();

            foreach (var mergeStatement in statementParser.Merges)
            {
                if (!(mergeStatement.MergeSpecification.Target is NamedTableReference))
                {
                    Log.WriteInfo("Error Parsing Merge Statement, Target is not a NamedTableReference");
                    continue;
                }

                var name  = (mergeStatement.MergeSpecification.Target as NamedTableReference).SchemaObject;
                var table = _tables.Get().FirstOrDefault(p => p.Name.EqualsName(name));
                if (table == null)
                {
                    Log.WriteInfo(
                        "Error Parsing Merge Statement, Could not find table name ({0}) in the TableRepository",
                        name.BaseIdentifier.Value);
                    continue;
                }

                if (!(mergeStatement.MergeSpecification.TableReference is InlineDerivedTable))
                {
                    Log.WriteInfo("Error Parsing Merge Statement, Could not find InlineDerivedTable");
                    continue;
                }


                var merge = new MergeDescriptor.Merge();
                merge.CustommMerger = mergeStatement;
                merge.Name          = name.ToIdentifier();

                merge.Data = GetDataFromMerge(mergeStatement, table);
                if (null == merge.Data)
                {
                    continue;   //can't do anything with this
                }

                merge.Data.AcceptChanges();
                merge.ScriptDescriptor = new InScriptDescriptor(mergeStatement.StartOffset,
                                                                mergeStatement.FragmentLength, _path);
                merge.Statement = mergeStatement;
                merge.Table     = table;


                bool hasSearchKeys   = false;
                var  searchCondition = mergeStatement.MergeSpecification.SearchCondition as BooleanComparisonExpression;
                if (null != searchCondition)
                {
                    var col = searchCondition.FirstExpression as ColumnReferenceExpression;
                    if (col != null)
                    {
                        var searchColName = col.MultiPartIdentifier.Identifiers.Last();
                        if (searchColName.Value == "???")
                        {
                            hasSearchKeys = false;
                        }
                        else
                        {
                            hasSearchKeys = true;
                        }
                    }
                }

                merge.Option =
                    new MergeOptions(
                        mergeStatement.MergeSpecification.ActionClauses.Any(p => p.Condition == MergeCondition.Matched),
                        mergeStatement.MergeSpecification.ActionClauses.Any(
                            p => p.Condition == MergeCondition.NotMatchedByTarget),
                        mergeStatement.MergeSpecification.ActionClauses.Any(
                            p => p.Condition == MergeCondition.NotMatchedBySource)
                        , hasSearchKeys
                        );

                Merges.Add(merge);
            }
        }
        public void Populate()
        {
            Merges = new List<MergeDescriptor.Merge>();
            var statementParser = new MergeStatementParser();

            var parser = new ScriptParser(statementParser, _path);
            parser.Parse();

            foreach (var mergeStatement in statementParser.Merges)
            {
                if (!(mergeStatement.MergeSpecification.Target is NamedTableReference))
                {
                    Log.WriteInfo("Error Parsing Merge Statement, Target is not a NamedTableReference");
                    continue;
                }

                var name = (mergeStatement.MergeSpecification.Target as NamedTableReference).SchemaObject;
                var table = _tables.Get().FirstOrDefault(p => p.Name.EqualsName(name));
                if (table == null)
                {
                    Log.WriteInfo(
                        "Error Parsing Merge Statement, Could not find table name ({0}) in the TableRepository",
                        name.BaseIdentifier.Value);
                    continue;
                }

                if (!(mergeStatement.MergeSpecification.TableReference is InlineDerivedTable))
                {
                    Log.WriteInfo("Error Parsing Merge Statement, Could not find InlineDerivedTable");
                    continue;
                }


                var merge = new MergeDescriptor.Merge();
                merge.CustommMerger = mergeStatement;
                merge.Name = name.ToIdentifier();
                
                merge.Data = GetDataFromMerge(mergeStatement, table);
                if (null == merge.Data)
                {
                    continue;   //can't do anything with this
                }
                
                merge.Data.AcceptChanges();
                merge.ScriptDescriptor = new InScriptDescriptor(mergeStatement.StartOffset,
                    mergeStatement.FragmentLength, _path);
                merge.Statement = mergeStatement;
                merge.Table = table;


                bool hasSearchKeys = false;
                var searchCondition = mergeStatement.MergeSpecification.SearchCondition as BooleanComparisonExpression;
                if (null != searchCondition)
                {
                    var col = searchCondition.FirstExpression as ColumnReferenceExpression;
                    if (col != null)
                    {
                        var searchColName = col.MultiPartIdentifier.Identifiers.Last();
                        if (searchColName.Value == "???")
                        {
                            hasSearchKeys = false;
                        }
                        else
                        {
                            hasSearchKeys = true;

                        }

                    }

                }

                merge.Option =
                    new MergeOptions(
                        mergeStatement.MergeSpecification.ActionClauses.Any(p => p.Condition == MergeCondition.Matched),
                        mergeStatement.MergeSpecification.ActionClauses.Any(
                            p => p.Condition == MergeCondition.NotMatchedByTarget),
                        mergeStatement.MergeSpecification.ActionClauses.Any(
                            p => p.Condition == MergeCondition.NotMatchedBySource)
                            ,hasSearchKeys
                            );

                Merges.Add(merge);
            }
        }