Example #1
0
        static void QueryWithEF_SQL()
        {
            var context = new Myefc_DB2Context();
            var data    = context.Customers.FromSqlRaw(@"SELECT * FROM Customers").AsNoTracking().ToList();

            Console.WriteLine(data.Count());
        }
Example #2
0
        static void QueryWithEF()
        {
            var context = new Myefc_DB2Context();
            var data    = context.Customers.ToList();

            Console.WriteLine(data.Count());
        }
Example #3
0
        static void QueryWithEF_SQL2()
        {
            var context = new Myefc_DB2Context();
            var conn    = new SqlConnection(@"Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=MyEFC_DB2;Integrated Security=True;Connect Timeout=30;Encrypt=False");
            var data    = conn.FromSQLRaw5 <Customers>(@"SELECT * FROM Customers");

            Console.WriteLine(data.Count());
        }
Example #4
0
        static void QueryWithEF_NoTrack()
        {
            var context = new Myefc_DB2Context();

            context.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking;
            var data = context.Customers.AsNoTracking().ToList();

            Console.WriteLine(data.Count());
        }
Example #5
0
        static void GenerateCustomersV1()
        {
            var context = new Myefc_DB2Context();

            context.Database.EnsureCreated();
            const string characters = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
            var          random     = new Random();

            for (int i = 0; i < 100000; i++)
            {
                context.Customers.Add(new Customers()
                {
                    Name         = new string(Enumerable.Repeat(characters, 10).Select(a => a[random.Next(a.Length)]).ToArray()),
                    Credit_Level = random.Next(5)
                });
            }
            context.SaveChanges();
        }