Esempio n. 1
0
        public static void Eager()
        {
            var db = new globalfactory2021Context();

            var manufacturer = db.Products
                               // Eager loaded
                               .Include(p => p.Manufacturer)
                               .First()
                               .Manufacturer;

            db.Dispose();
        }
        public static void SeedDataIfWasntSeededBefore()
        {
            var  db = new globalfactory2021Context();
            bool isDataAlreadySeeded = db.Manufacturers.Any(m => m.Name == ManufacturerName);

            if (isDataAlreadySeeded)
            {
                return;
            }

            SeedData(db);
        }
Esempio n. 3
0
            /// <summary>
            /// Key difference: IQueryable
            /// </summary>
            public static void Fast()
            {
                var db = new globalfactory2021Context();

                // IQueryable is a data structure still able to translate a C# expression to a SQL query.
                // SQL is much faster for lookups than C#.
                // 10 times faster.
                IQueryable <Product> products = db.Products;
                var filtered = products
                               .Where(p => p.Name == DataSeeding.TestProduct1Name)
                               .ToList();

                db.Dispose();
            }
        /// <summary>
        /// Key difference: format once
        /// </summary>
        public static void Fast()
        {
            var db = new globalfactory2021Context();

            // When using char or nchar- you will have a padded field
            // In order to find it, you will need to to make both sides:
            // filter and the column- to be of the same format
            // instead of trimming every column (n)
            // format the filter to match the formatting of a column (1)
            var filter   = DataSeeding.TestProduct2NameNotPadded.PadLeft(13);
            var filtered = db.Products
                           .Where(p => p.Name == filter)
                           .ToList();

            db.Dispose();
        }