예제 #1
0
        public IEnumerable <IngredientBinding> LoadIngredientGraph()
        {
            using (var session = GetStatelessSession())
            {
                IngredientForms    joinForm = null;
                Models.Ingredients joinIng  = null;

                var recIngs = session.QueryOver <RecipeIngredients>()
                              .JoinAlias(r => r.IngredientForm, () => joinForm)
                              .JoinAlias(r => r.Ingredient, () => joinIng)
                              .Where(p => joinIng.IngredientId != ShoppingList.GUID_WATER) // Ignore any usage for water
                              .Select(
                    p => joinIng.IngredientId,
                    p => p.Recipe.RecipeId,
                    p => p.Qty,
                    p => p.Unit,
                    p => joinIng.ConversionType,
                    p => joinIng.UnitWeight,
                    p => joinForm.UnitType,
                    p => joinForm.FormAmount,
                    p => joinForm.FormUnit)
                              .TransformUsing(IngredientGraphTransformer.Create())
                              .List <IngredientBinding>();

                return(recIngs);
            }
        }
예제 #2
0
        public IEnumerable <IngredientSource> LoadIngredientsForIndex()
        {
            using (var session = GetStatelessSession())
            {
                // Query for all ingredients, most used ingredients first
                // Note: Commenting out Linq query since there appears to be an NH bug with multiple ORDER BY clauses

                /*
                 * var ingredients = (from ing in session.Query<Ingredients>()
                 *                 orderby ((from p in session.Query<RecipeIngredients>()
                 *                          where p.Ingredient == ing
                 *                          select p.RecipeIngredientId).Count()) descending,
                 *                          ing.DisplayName ascending
                 *                 select new IngredientSource(ing.IngredientId, ing.DisplayName));
                 */

                Models.Ingredients ing = null;
                int?count      = null;
                var popularity = QueryOver.Of <RecipeIngredients>()
                                 .Where(p => p.Ingredient.IngredientId == ing.IngredientId)
                                 .ToRowCountQuery();

                var ingredients = session.QueryOver <Models.Ingredients>(() => ing)
                                  .SelectList(list => list
                                              .Select(p => p.IngredientId)
                                              .Select(p => p.DisplayName)
                                              .SelectSubQuery(popularity).WithAlias(() => count)
                                              )
                                  .OrderByAlias(() => count).Desc()
                                  .ThenBy(p => p.DisplayName).Asc()
                                  .List <Object[]>()
                                  .Select(i => new IngredientSource((Guid)i[0], (String)i[1]));

                return(ingredients.ToList());
            }
        }