private bool FilterDetailDerived1s(AI_DetailDerived1 entity)
 {
     return (entity.MasterID == this.ID);
 }
 private void DetachDetailDerived1s(AI_DetailDerived1 entity)
 {
     entity.Master = null;
 }
 private void AttachDetailDerived1s(AI_DetailDerived1 entity)
 {
     entity.Master = this;
 }
Esempio n. 4
0
        // Builds a single MasterDerived instance, returning it
        // in a collection
        private IEnumerable <AI_Master> BuildHierarchy()
        {
            int id = 0;
            AI_MasterDerived master = new AI_MasterDerived();

            master.ID = ++id;

            // Add the single-value associations
            AI_DetailDerived3 d3 = new AI_DetailDerived3()
            {
                ID       = ++id,
                Master   = master,
                MasterID = master.ID
            };

            master.DetailDerived3 = d3;

            AI_DetailDerived4 d4 = new AI_DetailDerived4()
            {
                ID       = ++id,
                Master   = master,
                MasterID = master.ID
            };

            master.DetailDerived4 = d4;

            // Add the multi-value associations
            List <AI_DetailDerived1> detailDerived1s = new List <AI_DetailDerived1>();
            List <AI_DetailDerived2> detailDerived2s = new List <AI_DetailDerived2>();

            AI_DetailDerived1 d1a = new AI_DetailDerived1()
            {
                ID       = ++id,
                Master   = master,
                MasterID = master.ID
            };

            AI_DetailDerived1 d1b = new AI_DetailDerived1()
            {
                ID       = ++id,
                Master   = master,
                MasterID = master.ID
            };

            AI_DetailDerived2 d2a = new AI_DetailDerived2()
            {
                ID       = ++id,
                Master   = master,
                MasterID = master.ID
            };

            master.DetailDerived1s = new List <AI_DetailDerived1>(new[] { d1a, d1b });

            AI_DetailDerived2 d2b = new AI_DetailDerived2()
            {
                ID       = ++id,
                Master   = master,
                MasterID = master.ID
            };

            master.DetailDerived2s = new List <AI_DetailDerived2>(new[] { d2a, d2b });

            return(new AI_Master[] { master });
        }
        // Builds a single MasterDerived instance, returning it
        // in a collection
        private IEnumerable<AI_Master> BuildHierarchy()
        {
            int id = 0;
            AI_MasterDerived master = new AI_MasterDerived();
            master.ID = ++id;

            // Add the single-value associations
            AI_DetailDerived3 d3 = new AI_DetailDerived3()
            {
                ID = ++id,
                Master = master,
                MasterID = master.ID
            };
            master.DetailDerived3 = d3;

            AI_DetailDerived4 d4 = new AI_DetailDerived4()
            {
                ID = ++id,
                Master = master,
                MasterID = master.ID
            };
            master.DetailDerived4 = d4;

            // Add the multi-value associations
            List<AI_DetailDerived1> detailDerived1s = new List<AI_DetailDerived1>();
            List<AI_DetailDerived2> detailDerived2s = new List<AI_DetailDerived2>();

            AI_DetailDerived1 d1a = new AI_DetailDerived1()
            {
                ID = ++id,
                Master = master,
                MasterID = master.ID
            };

            AI_DetailDerived1 d1b = new AI_DetailDerived1()
            {
                ID = ++id,
                Master = master,
                MasterID = master.ID
            };
   
            AI_DetailDerived2 d2a = new AI_DetailDerived2()
            {
                ID = ++id,
                Master = master,
                MasterID = master.ID
            };
            master.DetailDerived1s = new List<AI_DetailDerived1>(new[] { d1a, d1b });
 
            AI_DetailDerived2 d2b = new AI_DetailDerived2()
            {
                ID = ++id,
                Master = master,
                MasterID = master.ID
            };
            master.DetailDerived2s = new List<AI_DetailDerived2>(new[] { d2a, d2b });

            return new AI_Master[] { master };
        }
        public void Association_Inheritance_Modify_MultipleValue_Derived_Association()
        {
            AssociationInheritanceScenarios ctxt = new AssociationInheritanceScenarios(AssociationInheritanceScenarios_Uri);

            LoadOperation lo = ctxt.Load(ctxt.GetMastersQuery(), false);
            SubmitOperation so = null;

            EnqueueConditional(() => lo.IsComplete);
            EnqueueCallback(delegate
            {
                TestHelperMethods.AssertOperationSuccess(lo);

                AI_MasterDerived master = ctxt.AI_Masters.OfType<AI_MasterDerived>().FirstOrDefault();
                Assert.IsNotNull(master, "expected 1 master");

                // Verify we can remove one derived from the list
                AI_DetailDerived1 d1 = master.DetailDerived1s.First();
                master.DetailDerived1s.Remove(d1);
                Assert.AreEqual(1, master.DetailDerived1s.Count, "master.D1s.Remove didn't work");

                AI_DetailDerived1 newD1 = new AI_DetailDerived1();
                newD1.ID = 9999;

                master.DetailDerived1s.Add(newD1);
                Assert.AreEqual(2, master.DetailDerived1s.Count, "master.D1s.Add didn't work");

                AI_DetailDerived2 newD2 = new AI_DetailDerived2();
                newD2.ID = 99999;

                master.DetailDerived2s.Add(newD2);
                Assert.AreEqual(3, master.DetailDerived2s.Count, "master.D2s.Add didn't work");

                so = ctxt.SubmitChanges();
            });

            EnqueueConditional(() => so.IsComplete);
            EnqueueCallback(delegate
            {
                TestHelperMethods.AssertOperationSuccess(so);
            });

            EnqueueTestComplete();
        }