Esempio n. 1
0
        /// <summary>
        /// Performs the query to retrieve the category object specified
        /// by <paramref name="categoryId"/> and all notes in that category.
        /// </summary>
        /// <param name="categoryId">The identifier of the category to retrieve</param>
        private void RetrieveCategory(string categoryId)
        {
            // Open the BrightstarDB database using the shared connection string
            var context = new NotesContext(App.StoreConnectionString);

            // LINQ query to locate a category by its identifier
            TargetCategory = context.Categories.Where(x => x.CategoryId == categoryId).FirstOrDefault();
            
            var timer = new Stopwatch();
            timer.Start();

            // Sample LINQ query for all notes in a specific category
            Notes =
                context.Notes.Where(n => n.Category.CategoryId== categoryId).ToList();
            timer.Stop();

            TimingInfo = String.Format("Query returned {0} notes in the category in {1}ms", Notes.Count,
                                       timer.ElapsedMilliseconds);
        }
Esempio n. 2
0
        private string GenerateData(int count)
        {
            var context = new NotesContext(App.StoreConnectionString);
            var categories = new List<ICategory>();
            var rng = new Random();
            for(int i = 0; i < count/10;i++)
            {
                var category = context.Categories.Create();
                category.Label = String.Format("Generated Category #{0}", i + 1);
                categories.Add(category);
            }
            int catCount = categories.Count;

            for(int i = 0; i < count; i++)
            {
                var category = categories[rng.Next(catCount)];
                var note = context.Notes.Create();
                note.Category = category;
                note.Label = "Note " + DateTime.Now.Ticks;
                note.Content = "Lorem ipsum etc etc etc.";
            }
            context.SaveChanges();
            return categories[rng.Next(count/10)].CategoryId;
        }