Example #1
0
        public SqlQuery LeftJoin(string toTable, IAlias alias, ICriteria onCriteria)
        {
            if (alias == null)
                throw new ArgumentNullException("alias");

            if (string.IsNullOrEmpty(toTable))
                throw new ArgumentNullException("alias.table");

            var join = new LeftJoin(toTable, alias.Name, onCriteria);

            Join(join);

            var haveJoins = alias as IHaveJoins;
            if (haveJoins != null)
                AliasWithJoins[alias.Name] = haveJoins;

            return this;
        }
Example #2
0
        public LeftJoin ForeignJoin(Int32? foreignIndex = null)
        {
            if (ForeignTable.IsNullOrEmpty())
                throw new ArgumentNullException("ForeignTable");
            
            string foreignJoin;
            if (foreignIndex == null)
            {
                foreignJoin = Name;
                if (foreignJoin.EndsWith("Id", StringComparison.Ordinal))
                    foreignJoin = foreignJoin.Substring(0, foreignJoin.Length - 2);
                else if (foreignJoin.EndsWith("_ID", StringComparison.OrdinalIgnoreCase))
                    foreignJoin = foreignJoin.Substring(0, foreignJoin.Length - 3);

                foreignJoin = "j" + foreignJoin;
            }
            else
            {
                foreignJoin = foreignIndex.Value.TableAlias();
            }

            var joinKeyField = ForeignField ?? Name;
            var sourceAlias = "T0";
            var sourceKeyField = Name;

            var join = new LeftJoin(this.Fields.Joins, ForeignTable, foreignJoin,
                new Criteria(foreignJoin, joinKeyField) == new Criteria(sourceAlias, sourceKeyField));

            this.ForeignJoinAlias = join;
            return join;
        }