Ejemplo n.º 1
0
        /// <summary>
        /// Adds every publicly-settable field or property of the root entity to the select list, removing any beginning underscore from the name of the selected column.
        /// </summary>
        /// <returns>
        /// This RootQueryBuilder object.
        /// </returns>
        public RootQueryBuilder <T> Select(IEnumerable <Expression <Func <T, object> > > getterExprs)
        {
            // 1. Cache all setters for type T.
            IDictionary <string, SetValue> setters = CachedTypeData.FetchSettersOf <T>();

            // 2. Add "RootTable"."propOrFieldName" to the select list or just "propOrFieldName" if table_alias is null for every
            //    field and property returned in getterExprs
            foreach (Expression <Func <T, object> > getterExpr in getterExprs)
            {
                string propOrFieldName = ExpressionTreeHelper.GetPropOrFieldNameFromLambdaExpr <T>(getterExpr);

                // Only if there is a public setter for this property or if the field is public
                if (setters.ContainsKey(propOrFieldName) == false)
                {
                    continue;
                }

                // Remove a possible underscore before adding it to selection
                if (propOrFieldName[0] == '_')
                {
                    propOrFieldName = propOrFieldName.Substring(1);
                }

                string select_projection = RootTable + "." + propOrFieldName;
                Qb.Select(select_projection);
            }

            return(this);
        }
Ejemplo n.º 2
0
        public void AddOneToManyCollection <C>(Expression <Func <T, IList <C> > > fetchManyExpr, IDictionary <string, string> projectionsMap)
            where C : new()
        {
            if (FetchManyFetchers == null)
            {
                FetchManyFetchers = new Dictionary <string, ICollectionResultsFetcher <T> >();
            }

            string memberName = ExpressionTreeHelper.GetPropOrFieldNameFromLambdaExpr(fetchManyExpr);
            ICollectionResultsFetcher <T> collectionFetcher = new CollectionResultsFetcher <T, C>(projectionsMap);

            FetchManyFetchers.Add(memberName, collectionFetcher);
        }
Ejemplo n.º 3
0
        public MassUpdater(string table, Expression <Func <T, Object> > idGetterExpr, params Expression <Func <T, Object> >[] getterExprs)
        {
            this.table = table;

            chosenPropsOrFields = new Dictionary <string, GetValue>(getterExprs.Length);
            var tempGetters = CachedTypeData.FetchGettersOf <T>();

            // Only add the ones we want
            foreach (var getterExpr in getterExprs)
            {
                string propOrFieldName = ExpressionTreeHelper.GetPropOrFieldNameFromLambdaExpr <T>(getterExpr);
                chosenPropsOrFields.Add(propOrFieldName, tempGetters[propOrFieldName]);
            }
            // Add the id getter
            this.idColumn = ExpressionTreeHelper.GetPropOrFieldNameFromLambdaExpr <T>(idGetterExpr);
            this.idGetter = chosenPropsOrFields[idColumn];

            this.regs = new List <T>(50);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Joins a table that has already been queried or joined, of alias <paramref name="already_queried_table_alias"/> and represented by type <typeparamref name="JT1" />, to the table of name <paramref name="joined_table_name"/>, represented by type <typeparamref name="JT2" />.
        /// The join condition is the equality of columns associated to the properties expressed in <paramref name="alreadyQueriedTableColumnGetterExpr"/> and <paramref name="newlyJoinedTableColumnGetterExpr"/>.
        /// This method allows joining a table represented by a type more than once (through their different aliases).
        /// </summary>
        /// <param name="already_queried_table_alias">The alias of a table that has already been queried/joined.</param>
        /// <param name="joined_table_name">The real name of the table to be joined, as it is in the database.</param>
        /// <param name="joinType">The type of join (inner, outer etc.)</param>
        /// <param name="joinedTableAlias">An alias that has been defined for the joined table. Keep this in case you want to join this table to another (instead of joining the root table to something),</param>
        /// <typeparam name="JT1">The type that represents the table that has already been joined or queried.</typeparam>
        /// <typeparam name="JT2">The type of the newly joined table.</typeparam>
        public RootQueryBuilder <T> Join <JT1, JT2>(string already_queried_table_alias, string joined_table_name, Expression <Func <JT1, object> > alreadyQueriedTableColumnGetterExpr, Expression <Func <JT2, object> > newlyJoinedTableColumnGetterExpr, JoinType joinType, out string joined_table_alias)
        {
            if (QueriedTables.ContainsKey(already_queried_table_alias) == false)
            {
                throw new InvalidOperationException("The table alias \"" + already_queried_table_alias + "\" has not been queried prior to this method's invocation.");
            }
            else if (QueriedTables[already_queried_table_alias] != typeof(JT1))
            {
                throw new InvalidOperationException("The type \"" + typeof(JT1) + "\" does not match the type of the table whose alias is \"" + already_queried_table_alias + "\" (" + QueriedTables[already_queried_table_alias] + ").");
            }

            // Now that we know who is new, join'em!
            joined_table_alias = GetNewNameForQueriedTable(joined_table_name);
            AddQueriedTable(joined_table_alias, typeof(JT2));
            string column1 = already_queried_table_alias + "." + ExpressionTreeHelper.GetPropOrFieldNameFromLambdaExpr(alreadyQueriedTableColumnGetterExpr);
            string column2 = joined_table_alias + "." + ExpressionTreeHelper.GetPropOrFieldNameFromLambdaExpr(newlyJoinedTableColumnGetterExpr);

            Qb.Join(joined_table_name, column1, column2, joinType);

            return(this);
        }
Ejemplo n.º 5
0
        public void Update <T>(string table, Object obj, Expression <Func <T, Object> > idGetterExpr, params Expression <Func <T, Object> >[] getterExprs)
        {
            ObjectAndColumns reg = new ObjectAndColumns {
                table = table,
                chosenPropsOrFields = new Dictionary <string, GetValue>(getterExprs.Length),
                idColumn            = ExpressionTreeHelper.GetPropOrFieldNameFromLambdaExpr <T>(idGetterExpr),
                obj = obj
            };

            var tempGetters = CachedTypeData.FetchGettersOf <T>();

            // Only add the ones we want
            foreach (var getterExpr in getterExprs)
            {
                string propOrFieldName = ExpressionTreeHelper.GetPropOrFieldNameFromLambdaExpr <T>(getterExpr);
                reg.chosenPropsOrFields.Add(propOrFieldName, tempGetters[propOrFieldName]);
            }
            // Add the id getter
            reg.idGetter = tempGetters[reg.idColumn];

            regs.Add(reg);
        }