コード例 #1
0
        private void StartsWithTextBox_TextChanged(object sender, TextChangedEventArgs e)
        {
            ResultsListBox.Items.Clear();

            if (string.IsNullOrWhiteSpace(StartsWithTextBox.Text))
            {
                return;
            }

            using (var ctx = new MealsContext())
            {
                var results =
                    (from dish in ctx.Meals
                     .Include("Ingredients")
                     where dish.Name.StartsWith(
                         StartsWithTextBox.Text)
                     orderby dish.Name
                     select dish)
                    .ToList();

                foreach (var result in results)
                {
                    string recipe = result.Name + ": " + string.Join(", ", result.Ingredients.Select(ing => ing.Description));
                    ResultsListBox.Items.Add(recipe);
                }
            }
        }
コード例 #2
0
        private void InitializeMenu()
        {
            using (var ctx = new MealsContext())
            {
                var meals =
                    (from meal in ctx.Meals
                     select meal.Name)
                    .ToList();

                MenuListBox.ItemsSource = meals;
            }
        }