コード例 #1
0
ファイル: SqlDialect.cs プロジェクト: abrobston/DB
 public virtual string JoinSql(SqlJoinDefinition join)
 {
     return string.Format("{0} join {1} {2} on {3}={4}",
                     join.Type == SqlJoinType.Inner ? "inner" : "left outer",
                     QuoteTable(@join.Right.Schema.MappedName),
                     join.Right.Alias,
                     QuoteField(join.Left.Alias + "." + @join.Left.Field.MappedName),
                     QuoteField(join.Right.Alias + "." + @join.Right.Field.MappedName)
                     );
 }
コード例 #2
0
        private string ProcessRelation(Expression fullExpression, Expression leftExpression, string memberName)
        {
            var parentMetaData = _metaData[leftExpression];

            if (parentMetaData != null)
            {
                if (_metaData.ContainsKey(fullExpression))
                    return null; // relation already visited

                var iterator = GetRootIterator(parentMetaData.Iterator);

                var relation = parentMetaData.Schema.Relations[memberName];
                var leftAlias = _relationAliases[iterator][parentMetaData.Key];

                if (relation != null && relation.IsToOne)
                {
                    if (!_relationAliases[iterator].ContainsKey(relation))
                    {
                        var sqlJoin = new SqlJoinDefinition(
                            new SqlJoinPart(parentMetaData.Schema, relation.LocalField, leftAlias),
                            new SqlJoinPart(relation.ForeignSchema, relation.ForeignField, SqlNameGenerator.NextTableAlias())
                            );

                        CurrentQuery.Joins.Add(sqlJoin);

                        _relationAliases[iterator][relation] = sqlJoin.Right.Alias;
                    }

                    _metaData[fullExpression] = new ExpressionMetaData { Iterator = iterator, Relation = relation, Schema = relation.ForeignSchema };
                }
                else if (relation == null)
                {
                    return leftAlias + "." + memberName;
                }
            }

            return null;
        }