Пример #1
0
        public void EFFK_InsertAddRelated()
        {
            var newCust = new EFFKClient.Customer()
            {
                ID = 11, EditTimeStamp = new byte[] { 0 }
            };
            var newOrder1 = new EFFKClient.Order()
            {
                ID = 100020, CustomerId = 11
            };
            var newOrder2 = new EFFKClient.Order()
            {
                ID = 100021, CustomerId = 1
            };
            var newOrder3 = new EFFKClient.Order()
            {
                ID = 100022
            };

            ctx.AddObject("CustomObjectContext.Customers", newCust);
            ctx.AddRelatedObject(newCust, "Orders", newOrder1);
            ctx.AddRelatedObject(newCust, "Orders", newOrder2);
            ctx.AddRelatedObject(newCust, "Orders", newOrder3);

            ctx.SaveChanges();

            VerifyServerOrderId(100020, 11);
            VerifyServerOrderId(100021, 11);
            VerifyServerOrderId(100022, 11);
        }
Пример #2
0
        public void EFFK_InsertAddRelated()
        {
            var newCust = new EFFKClient.Customer() { ID = 11, EditTimeStamp = new byte[] { 0 } };
            var newOrder1 = new EFFKClient.Order() { ID = 100020, CustomerId = 11 };
            var newOrder2 = new EFFKClient.Order() { ID = 100021, CustomerId = 1 };
            var newOrder3 = new EFFKClient.Order() { ID = 100022 };

            ctx.AddObject("CustomObjectContext.Customers", newCust);
            ctx.AddRelatedObject(newCust, "Orders", newOrder1);
            ctx.AddRelatedObject(newCust, "Orders", newOrder2);
            ctx.AddRelatedObject(newCust, "Orders", newOrder3);

            ctx.SaveChanges();

            VerifyServerOrderId(100020, 11);
            VerifyServerOrderId(100021, 11);
            VerifyServerOrderId(100022, 11);
        }
Пример #3
0
        public void EFFK_InsertTest()
        {
            var newCust = new EFFKClient.Customer()
            {
                ID = 10, Name = "New Cust", EditTimeStamp = new byte[] { 0, 1, 2, 3 }
            };
            var cust1 = ctx.CreateQuery <EFFKClient.Customer>("CustomObjectContext.Customers").Where(c => c.ID == 1).FirstOrDefault();

            var orders = new Tuple <EFFKClient.Order, int>[]
            {
                Tuple.Create(new EFFKClient.Order()
                {
                    ID = 100000, Customers = null
                }, 0),                                                                                          // Set None
                Tuple.Create(new EFFKClient.Order()
                {
                    ID = 100007, CustomerId = 10
                }, 10),                                                                                         // Set FK only, new
                Tuple.Create(new EFFKClient.Order()
                {
                    ID = 100008, Customers = newCust
                }, 10),                                                                                         // Set Nav only, new
                Tuple.Create(new EFFKClient.Order()
                {
                    ID = 100009, CustomerId = 10, Customers = newCust
                }, 10),                                                                                         // Set FK + Nav to same, new
                Tuple.Create(new EFFKClient.Order()
                {
                    ID = 100010, CustomerId = 1, Customers = newCust
                }, 10),                                                                                         // Set FK + Nav to diff, new

                // Order Object | Expected Customer ID
                Tuple.Create(new EFFKClient.Order()
                {
                    ID = 100001, CustomerId = 1, Customers = null
                }, 1),                                                                                          // Set FK only
                Tuple.Create(new EFFKClient.Order()
                {
                    ID = 100002, Customers = cust1
                }, 1),                                                                                          // Set Nav only
                Tuple.Create(new EFFKClient.Order()
                {
                    ID = 100003, CustomerId = 1, Customers = cust1
                }, 1),                                                                                          // Set FK + Nav to same
                Tuple.Create(new EFFKClient.Order()
                {
                    ID = 100004, CustomerId = 2, Customers = null
                }, 1),                                                                                          // Set FK + Nav to diff
                Tuple.Create(new EFFKClient.Order()
                {
                    ID = 100005, CustomerId = 2, Customers = cust1
                }, 1),                                                                                          // Set FK + Nav to diff
                Tuple.Create(new EFFKClient.Order()
                {
                    ID = 100006, CustomerId = 2, Customers = newCust
                }, 1),                                                                                          // Set FK + Nav to diff
            };

            ctx.AddObject("CustomObjectContext.Customers", newCust);
            foreach (var t in orders)
            {
                ctx.AddObject("CustomObjectContext.Orders", t.Item1);
                if (t.Item1.CustomerId == 2)
                {
                    ctx.SetLink(t.Item1, "Customers", cust1);
                }
                else if (t.Item1.Customers != null)
                {
                    ctx.SetLink(t.Item1, "Customers", t.Item1.Customers);
                }
                ctx.SaveChanges();

                if (t.Item2 == 0)
                {
                    VerifyServerOrderId(t.Item1.ID, null);
                }
                else
                {
                    VerifyServerOrderId(t.Item1.ID, t.Item2);
                }
            }
        }
Пример #4
0
        public void EFFK_InsertTest()
        {
            var newCust = new EFFKClient.Customer() { ID = 10, Name = "New Cust", EditTimeStamp = new byte[] { 0, 1, 2, 3 } };
            var cust1 = ctx.CreateQuery<EFFKClient.Customer>("CustomObjectContext.Customers").Where(c => c.ID == 1).FirstOrDefault();

            var orders = new Tuple<EFFKClient.Order, int>[]
            {
                Tuple.Create(new EFFKClient.Order(){ ID=100000, Customers=null },  0),                          // Set None
                Tuple.Create(new EFFKClient.Order(){ ID=100007, CustomerId =10 }, 10),                          // Set FK only, new
                Tuple.Create(new EFFKClient.Order(){ ID=100008, Customers = newCust }, 10),                     // Set Nav only, new
                Tuple.Create(new EFFKClient.Order(){ ID=100009, CustomerId =10, Customers=newCust }, 10),       // Set FK + Nav to same, new
                Tuple.Create(new EFFKClient.Order(){ ID=100010, CustomerId =1, Customers=newCust }, 10),        // Set FK + Nav to diff, new

                // Order Object | Expected Customer ID
                Tuple.Create(new EFFKClient.Order(){ ID=100001, CustomerId =1, Customers=null },  1),           // Set FK only
                Tuple.Create(new EFFKClient.Order(){ ID=100002, Customers=cust1 },  1),                         // Set Nav only
                Tuple.Create(new EFFKClient.Order(){ ID=100003, CustomerId =1, Customers=cust1 }, 1),           // Set FK + Nav to same
                Tuple.Create(new EFFKClient.Order(){ ID=100004, CustomerId =2, Customers=null }, 1),            // Set FK + Nav to diff
                Tuple.Create(new EFFKClient.Order(){ ID=100005, CustomerId =2, Customers=cust1 }, 1),           // Set FK + Nav to diff
                Tuple.Create(new EFFKClient.Order(){ ID=100006, CustomerId =2, Customers=newCust }, 1),         // Set FK + Nav to diff
            };

            ctx.AddObject("CustomObjectContext.Customers", newCust);
            foreach (var t in orders)
            {
                ctx.AddObject("CustomObjectContext.Orders", t.Item1);
                if (t.Item1.CustomerId == 2)
                {
                    ctx.SetLink(t.Item1, "Customers", cust1);
                }
                else if (t.Item1.Customers != null)
                {
                    ctx.SetLink(t.Item1, "Customers", t.Item1.Customers);
                }
                ctx.SaveChanges();

                if (t.Item2 == 0)
                {
                    VerifyServerOrderId(t.Item1.ID, null);
                }
                else
                {
                    VerifyServerOrderId(t.Item1.ID, t.Item2);
                }
            }
        }