Beispiel #1
0
        /// <summary>
        /// Gets a JOIN QueryPredicate based on a LINQ Expression with two parameters.
        /// </summary>
        /// <returns>The JOIN QueryPredicate.</returns>
        /// <param name="expression">The expression to be translated.</param>
        /// <typeparam name="T1">Left entity involved in the JOIN (it must inherit from IEntity class).</typeparam>
        /// <typeparam name="T2">Right entity involved in the JOIN (it must inherit from IEntity class).</typeparam>
        public void Join <T1, T2>(JoinType joinType, Expression <Func <T1, T2, bool> > expression, EntitySet <T1> entitySet1, EntitySet <T2> entitySet2) where T1 : class, IEntity, new() where T2 : class, IEntity, new()
        {
            T1     entity1    = new T1();
            T2     entity2    = new T2();
            string parameter1 = expression.Parameters[0].Name;
            string parameter2 = expression.Parameters[1].Name;

            if (joinType != JoinType.Inner && Parameters.Contains(parameter2))
            {
                throw new Exception($"Alias '" + parameter2 + " already used within a " + GetJoinType(JoinTypeDictionary[parameter2]) + "' operator. No further use with RIGHT JOIN or LEFT JOIN is allowed.");
            }

            SQLPredicate queryPredicate = QueryTranslator.Translate(Evaluator.PartialEval(expression), i);

            i += queryPredicate.Parameters.Count;
            AddParameter(parameter1, entity1, typeof(EntitySet <T1>), typeof(T1), entitySet1, joinType);
            AddParameter(parameter2, entity2, typeof(EntitySet <T2>), typeof(T2), entitySet2, joinType);
            if (AddingOrder[parameter1] > AddingOrder[parameter2])
            {
                QueryDictionary[parameter1].Add(queryPredicate);
            }
            else
            {
                QueryDictionary[parameter2].Add(queryPredicate);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Uses QueryTranslator to translate a LINQ Expression to a SQL query.
        /// </summary>
        /// <returns>The sql query.</returns>
        /// <param name="expression">The LINQ Expression to be translated.</param>
        /// <typeparam name="T">The 1st type parameter.</typeparam>
        private SQLPredicate Translate(Expression expression, bool ignoreAliases = false)
        {
            ISQLTranslator sql  = SQLTranslatorFactory.GetTranslator(DbType);
            SQLPredicate   pred = sql.Translate(Evaluator.PartialEval(expression), 0, ignoreAliases);

            return(pred);
        }
Beispiel #3
0
        /// <summary>
        /// Uses QueryTranslator to translate a LINQ Expression to a SQL query.
        /// </summary>
        /// <returns>The sql query.</returns>
        /// <param name="expression">The LINQ Expression to be translated.</param>
        /// <typeparam name="T">The 1st type parameter.</typeparam>
        private SQLPredicate Translate(Expression expression)
        {
            ISQLTranslator sql  = SQLTranslatorFactory.GetTranslator(DbType);
            SQLPredicate   pred = sql.Translate(Evaluator.PartialEval(expression));

            return(pred);
        }