Beispiel #1
0
        internal static EntityConnection CreateTableAndPopulateData(Type contextType)
        {
            // clear the old connection
            entityConnection = null;
            EntityConnection.Open();
            CreateTable((SqlConnection)EntityConnection.StoreConnection);
            CustomObjectContextPOCOProxy context = (CustomObjectContextPOCOProxy)Activator.CreateInstance(contextType);

            Populate(context);
            return(EntityConnection);
        }
Beispiel #2
0
        private static void Populate(CustomObjectContextPOCOProxy context)
        {
            Customer[] customers = new Customer[3];
            for (int i = 0; i < customers.Length; i++)
            {
                Customer customer = (i % 2 == 0) ? new Customer() : new CustomerWithBirthday();
                customer.ID = i;
                customer.Name = "Customer " + i.ToString();
                customer.Concurrency = i.ToString();

                customer.Address = new Address()
                {
                    StreetAddress = "Line1",
                    City = "Redmond",
                    State = "WA",
                    PostalCode = "98052"
                };

                if (customer.GetType() == typeof(CustomerWithBirthday))
                {
                    ((CustomerWithBirthday)customer).Birthday = DateTime.Now;
                }

                if (i > 0)
                {
                    customer.BestFriend = customers[i - 1];
                }

                Order o1 = new Order();
                o1.ID = i;
                o1.DollarAmount = 20.1;

                Order o2 = new Order();
                o2.ID = i + 100;
                o2.DollarAmount = 30.2;

                customer.Orders.Add(o1);
                customer.Orders.Add(o2);
                context.AddObject("CustomObjectContext.Customers", customer);
                customers[i] = customer;
            }

            CustomerBlob[] customerBlobs = new CustomerBlob[3];
            for (int i = 0; i < customerBlobs.Length; i++)
            {
                CustomerBlob customer = (i % 2 == 0) ? new CustomerBlob() : new CustomerBlobWithBirthday();
                customer.ID = i;
                customer.Name = "CustomerBlob " + i.ToString();
                customer.Concurrency = i.ToString();

                if (customer.GetType() == typeof(CustomerBlobWithBirthday))
                {
                    ((CustomerBlobWithBirthday)customer).Birthday = DateTime.Now;
                }

                context.AddObject("CustomObjectContext.CustomerBlobs", customer);
                customerBlobs[i] = customer;
            }

            context.SaveChanges();
        }
Beispiel #3
0
        private static void Populate(CustomObjectContextPOCOProxy context)
        {
            Customer[] customers = new Customer[3];
            for (int i = 0; i < customers.Length; i++)
            {
                Customer customer = (i % 2 == 0) ? new Customer() : new CustomerWithBirthday();
                customer.ID          = i;
                customer.Name        = "Customer " + i.ToString();
                customer.Concurrency = i.ToString();

                customer.Address = new Address()
                {
                    StreetAddress = "Line1",
                    City          = "Redmond",
                    State         = "WA",
                    PostalCode    = "98052"
                };

                if (customer.GetType() == typeof(CustomerWithBirthday))
                {
                    ((CustomerWithBirthday)customer).Birthday = DateTime.Now;
                }

                if (i > 0)
                {
                    customer.BestFriend = customers[i - 1];
                }

                Order o1 = new Order();
                o1.ID           = i;
                o1.DollarAmount = 20.1;

                Order o2 = new Order();
                o2.ID           = i + 100;
                o2.DollarAmount = 30.2;

                customer.Orders.Add(o1);
                customer.Orders.Add(o2);
                context.AddObject("CustomObjectContext.Customers", customer);
                customers[i] = customer;
            }

            CustomerBlob[] customerBlobs = new CustomerBlob[3];
            for (int i = 0; i < customerBlobs.Length; i++)
            {
                CustomerBlob customer = (i % 2 == 0) ? new CustomerBlob() : new CustomerBlobWithBirthday();
                customer.ID          = i;
                customer.Name        = "CustomerBlob " + i.ToString();
                customer.Concurrency = i.ToString();

                if (customer.GetType() == typeof(CustomerBlobWithBirthday))
                {
                    ((CustomerBlobWithBirthday)customer).Birthday = DateTime.Now;
                }

                context.AddObject("CustomObjectContext.CustomerBlobs", customer);
                customerBlobs[i] = customer;
            }

            context.SaveChanges();
        }