// 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 };
        }
 private bool FilterDetailDerived3(AI_DetailDerived3 entity)
 {
     return (entity.MasterID == this.ID);
 }
Example #3
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 });
        }
        public void Association_Inheritance_Modify_Singleton_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 one master");

                AI_DetailDerived3 d3 = master.DetailDerived3;
                Assert.IsNotNull(d3, "no master.D3");
                Assert.AreSame(master, d3.Master, "wrong master.D3");

                // Verify we can unset it
                master.DetailDerived3 = null;
                Assert.IsNull(master.DetailDerived3, "could not reset master.D4");

                AI_DetailDerived3 newD3 = new AI_DetailDerived3();
                newD3.ID = 99;
                master.DetailDerived3 = newD3;

                AI_DetailDerived4 newD4 = new AI_DetailDerived4();
                newD4.ID = 999;
                master.DetailDerived4 = newD4;

                so = ctxt.SubmitChanges();
            });

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

            EnqueueTestComplete();
        }