当前位置: 首页>>代码示例>>C#>>正文


C# XrmServiceContext.AddObject方法代码示例

本文整理汇总了C#中XrmServiceContext.AddObject方法的典型用法代码示例。如果您正苦于以下问题:C# XrmServiceContext.AddObject方法的具体用法?C# XrmServiceContext.AddObject怎么用?C# XrmServiceContext.AddObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在XrmServiceContext的用法示例。


在下文中一共展示了XrmServiceContext.AddObject方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

		static void Main(string[] args)
		{
			var xrm = new XrmServiceContext("Xrm");
			
			WriteExampleContacts(xrm);

			//create a new contact called Allison Brown
			var allisonBrown = new Xrm.Contact
			{
				FirstName = "Allison",
				LastName = "Brown",
				Address1_Line1 = "23 Market St.",
				Address1_City = "Sammamish",
				Address1_StateOrProvince = "MT",
				Address1_PostalCode = "99999",
				Telephone1 = "12345678",
				EMailAddress1 = "[email protected]"
			};

			xrm.AddObject(allisonBrown);
			xrm.SaveChanges();

			WriteExampleContacts(xrm);

			Console.WriteLine("Press any key to exit.");
			Console.ReadKey();
		}
开发者ID:cesugden,项目名称:Scripts,代码行数:27,代码来源:Program.cs

示例2: When_calling_context_add_and_save_changes_entity_is_added_to_the_faked_context

        public void When_calling_context_add_and_save_changes_entity_is_added_to_the_faked_context()
        {
            var context = new XrmFakedContext();
            var service = context.GetFakedOrganizationService();

            using(var ctx = new XrmServiceContext(service))
            {
                ctx.AddObject(new Account() { Name = "Test account" });
                ctx.SaveChanges();

                var account = ctx.CreateQuery<Account>()
                            .ToList()
                            .FirstOrDefault();

                Assert.Equal("Test account", account.Name);
            }
        }
开发者ID:ccellar,项目名称:fake-xrm-easy,代码行数:17,代码来源:OrgServiceContextTests.cs

示例3: bw_DoWork

        private void bw_DoWork(object sender, DoWorkEventArgs e)
        {
            XrmServiceContext xrm;

            xrm = new XrmServiceContext("Xrm");

            foreach (MyLead objLead in Leads)
            {
                //xrm.AddObject(objLead);
                Guid objLeadGuid = xrm.Create(objLead);//Using this method as opposed to xrm.AddObject results in getting the GUID required to add a note to the lead.
                                                        //This method also adds the Lead Object to the Db.
                objLead.Note.ObjectId = new Microsoft.Xrm.Client.CrmEntityReference("lead", objLeadGuid); //Creates the xref between the Annotation object (the note) and the lead
                xrm.AddObject(objLead.Note); //adds the note to the CRM Database..
            }

            xrm.SaveChanges();//this saves all the notes to the database.  The leads are automatically saved by calling the Create() method...
        }
开发者ID:JakeLardinois,项目名称:CRM,代码行数:17,代码来源:frmAddLeads.cs

示例4: When_calling_context_add_addrelated_and_save_changes_entities_are_added_to_the_faked_context

        public void When_calling_context_add_addrelated_and_save_changes_entities_are_added_to_the_faked_context()
        {
            var context = new XrmFakedContext();

            var relationship = new XrmFakedRelationship()
            {
                IntersectEntity = "accountleads",
                Entity1Attribute = "accountid",
                Entity2Attribute = "leadid",
                Entity1LogicalName = "account",
                Entity2LogicalName = "lead"
            };
            context.AddRelationship("accountleads", relationship);

            var service = context.GetFakedOrganizationService();

            using (var ctx = new XrmServiceContext(service))
            {
                var account = new Account() { Name = "Test account" };
                ctx.AddObject(account);

                var contact = new Lead() { FirstName = "Jane", LastName = "Doe" };
                ctx.AddRelatedObject(account, new Relationship("accountleads"), contact);
                var result = ctx.SaveChanges();

                var resultaccount = ctx.CreateQuery<Account>()
                                       .ToList()
                                       .FirstOrDefault();

                Assert.NotNull(resultaccount);
                Assert.Equal("Test account", resultaccount.Name);

                var reaultlead = ctx.CreateQuery<Lead>()
                                    .ToList()
                                    .FirstOrDefault();

                Assert.NotNull(reaultlead);
                Assert.Equal("Jane", reaultlead.FirstName);
                Assert.Equal("Doe", reaultlead.LastName);

                var relationshipRecords = ctx.CreateQuery("accountleads")
                                             .ToList();
                Assert.NotEmpty(relationshipRecords);
            }
        }
开发者ID:DigitalFlow,项目名称:fake-xrm-easy,代码行数:45,代码来源:OrgServiceContextTests.cs

示例5: When_calling_context_add_and_save_changes_returns_correct_result

        public void When_calling_context_add_and_save_changes_returns_correct_result()
        {
            var context = new XrmFakedContext();
            var service = context.GetFakedOrganizationService();

            using (var ctx = new XrmServiceContext(service))
            {
                ctx.AddObject(new Account() { Name = "Test account" });
                var result = ctx.SaveChanges();

                Assert.NotNull(result);
                Assert.NotEmpty(result);
                Assert.Equal("Create", result.First().Response.ResponseName);
                Assert.IsType<CreateResponse>(result.First().Response);
                Assert.NotEqual(Guid.Empty, ((CreateResponse)result.First().Response).id);
            }
        }
开发者ID:DigitalFlow,项目名称:fake-xrm-easy,代码行数:17,代码来源:OrgServiceContextTests.cs

示例6: addContact

        static private void addContact()
        {
            var xrm = new XrmServiceContext("Xrm");

            listContacts(xrm);
            //Create a new contact called Allison Brown.
            var allisonBrown = new Xrm.Contact
            {
                FirstName = "Allison",
                LastName = "Brown 2",
                Address1_Line1 = "23 Market St.",
                Address1_City = "Sammamish",
                Address1_StateOrProvince = "MT",
                Address1_PostalCode = "99999",
                Telephone1 = "12345678",
                EMailAddress1 = "[email protected]"
            };

            xrm.AddObject(allisonBrown);
            xrm.SaveChanges();

            listContacts(xrm);

        }
开发者ID:Phil-Ruben,项目名称:CRM,代码行数:24,代码来源:Program.cs


注:本文中的XrmServiceContext.AddObject方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。