• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# XrmServiceContext类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: XrmFakedContext

        public void When_doing_a_crm_linq_query_and_proxy_types_and_a_selected_attribute_returned_projected_entity_is_thesubclass()
        {
            var fakedContext = new XrmFakedContext();
            var guid1 = Guid.NewGuid();
            var guid2 = Guid.NewGuid();

            fakedContext.Initialize(new List<Entity>() {
                new Contact() { Id = guid1, FirstName = "Jordi" },
                new Contact() { Id = guid2, FirstName = "Other" }
            });

            var service = fakedContext.GetFakedOrganizationService();

            using (XrmServiceContext ctx = new XrmServiceContext(service))
            {
                var matches = (from c in ctx.CreateQuery<Contact>()
                               where c.FirstName.Equals("Jordi")
                               select new
                               {
                                   FirstName = c.FirstName,
                                   CrmRecord = c
                               }).ToList();

                Assert.True(matches.Count == 1);
                Assert.True(matches[0].FirstName.Equals("Jordi"));
                Assert.IsAssignableFrom(typeof(Contact), matches[0].CrmRecord);
                Assert.True(matches[0].CrmRecord.GetType() == typeof(Contact));

            }
        }
开发者ID:DigitalFlow,项目名称:fake-xrm-easy,代码行数:30,代码来源:FakeContextTestLinqQueries.cs


示例2: UpdateBaselineProjection

        public void UpdateBaselineProjection(CustomBaselineProjection bp)
        {
            using (var ctx = new XrmServiceContext("Xrm"))
            {
                var bps = (from s in ctx.new_baselineprojectionsSet
                            where s.Id == bp.Id
                            select s).FirstOrDefault();
                bps.new_name = bp.Name;

                bps.new_Year = bp.Year;
                bps.new_CA_Q1Actual = (int)bp.CA_Q1_A;
                bps.new_Q1_ca = (decimal)bp.CA_Q1_P;
                bps.new_CA_Q2Actual = (int)bp.CA_Q2_A;
                bps.new_Q2_ca = (decimal)bp.CA_Q2_P;
                bps.new_CA_Q3Actual = (int)bp.CA_Q3_A;
                bps.new_Q3_ca = (decimal)bp.CA_Q3_P;
                bps.new_CA_Q4Actual = (int)bp.CA_Q4_A;
                bps.new_Q4_ca = (decimal)bp.CA_Q4_P;

                bps.new_DB_Q1Actual = (int)bp.DB_Q1_A;
                bps.new_Q1_db = (decimal)bp.DB_Q1_P;
                bps.new_DB_Q2Actual = (int)bp.DB_Q2_A;
                bps.new_Q2_db = (decimal)bp.DB_Q2_P;
                bps.new_DB_Q3Actual = (int)bp.DB_Q3_A;
                bps.new_Q3_db = (decimal)bp.DB_Q3_P;
                bps.new_DB_Q4Actual = (int)bp.DB_Q4_A;
                bps.new_Q4_db = (decimal)bp.DB_Q4_P;

                ctx.UpdateObject(bps);
                ctx.SaveChanges();
            }
        }
开发者ID:meanprogrammer,项目名称:ADBCRM2,代码行数:32,代码来源:BaselineProjectionService.svc.cs


示例3: When_doing_a_crm_linq_query_with_an_equals_operator_record_is_returned

        public void When_doing_a_crm_linq_query_with_an_equals_operator_record_is_returned()
        {
            var fakedContext = new XrmFakedContext();
            var guid1 = Guid.NewGuid();
            var guid2 = Guid.NewGuid();

            fakedContext.Initialize(new List<Entity>() {
                new Contact() { Id = guid1, FirstName = "Jordi" },
                new Contact() { Id = guid2, FirstName = "Other" }
            });

            var service = fakedContext.GetFakedOrganizationService();

            using (XrmServiceContext ctx = new XrmServiceContext(service))
            {
                var matches = (from c in ctx.CreateQuery<Contact>()
                               where c.FirstName.Equals("Jordi")
                               select c).ToList();

                Assert.True(matches.Count == 1);
                Assert.True(matches[0].FirstName.Equals("Jordi"));

                matches = (from c in ctx.CreateQuery<Contact>()
                               where c.FirstName == "Jordi" //Using now equality operator
                               select c).ToList();

                Assert.True(matches.Count == 1);
                Assert.True(matches[0].FirstName.Equals("Jordi"));
            }
            
        }
开发者ID:ccellar,项目名称:fake-xrm-easy,代码行数:31,代码来源:FakeContextTestLinqQueries.cs


示例4: When_doing_a_crm_linq_query_and_proxy_types_projection_must_be_applied_after_where_clause

        public void When_doing_a_crm_linq_query_and_proxy_types_projection_must_be_applied_after_where_clause()
        {
            var fakedContext = new XrmFakedContext();
            fakedContext.ProxyTypesAssembly = Assembly.GetExecutingAssembly();

            var guid1 = Guid.NewGuid();
            var guid2 = Guid.NewGuid();

            fakedContext.Initialize(new List<Entity>() {
                new Contact() { Id = guid1, FirstName = "Jordi", LastName = "Montana" },
                new Contact() { Id = guid2, FirstName = "Other" }
            });

            var service = fakedContext.GetFakedOrganizationService();

            using (XrmServiceContext ctx = new XrmServiceContext(service))
            {
                var matches = (from c in ctx.CreateQuery<Contact>()
                               where c.LastName == "Montana"  //Should be able to filter by a non-selected attribute
                               select new
                               {
                                   FirstName = c.FirstName
                               }).ToList();

                Assert.True(matches.Count == 1);
                Assert.True(matches[0].FirstName.Equals("Jordi"));
            }
        }
开发者ID:DigitalFlow,项目名称:fake-xrm-easy,代码行数:28,代码来源:FakeContextTestLinqQueries.cs


示例5: CreateXrmServiceContext

        protected XrmServiceContext CreateXrmServiceContext(MergeOption? mergeOption = null)
        {
            //string organizationUri = ConfigurationManager.AppSettings["CRM_OrganisationUri"];

            string organizationUri = "https://existornest2.api.crm4.dynamics.com/XRMServices/2011/Organization.svc";

            IServiceManagement<IOrganizationService> OrganizationServiceManagement = ServiceConfigurationFactory.CreateManagement<IOrganizationService>(new Uri(organizationUri));
            AuthenticationProviderType OrgAuthType = OrganizationServiceManagement.AuthenticationType;
            AuthenticationCredentials authCredentials = GetCredentials(OrgAuthType);
            AuthenticationCredentials tokenCredentials = OrganizationServiceManagement.Authenticate(authCredentials);
            OrganizationServiceProxy organizationProxy = null;
            SecurityTokenResponse responseToken = tokenCredentials.SecurityTokenResponse;

            if (ConfigurationManager.AppSettings["CRM_AuthenticationType"] == "ActiveDirectory")
            {
                using (organizationProxy = new OrganizationServiceProxy(OrganizationServiceManagement, authCredentials.ClientCredentials))
                {
                    organizationProxy.EnableProxyTypes();
                }
            }
            else
            {
                using (organizationProxy = new OrganizationServiceProxy(OrganizationServiceManagement, responseToken))
                {
                    organizationProxy.EnableProxyTypes();
                }
            }

            IOrganizationService service = (IOrganizationService)organizationProxy;

            var context = new XrmServiceContext(service);
            if (context != null && mergeOption != null) context.MergeOption = mergeOption.Value;
            return context;
        }
开发者ID:existornest,项目名称:crmCRUD,代码行数:34,代码来源:ConnectionContext.cs


示例6: 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


示例7: When_using_proxy_types_assembly_the_attribute_metadata_is_inferred_from_the_proxy_types_assembly

        public static void When_using_proxy_types_assembly_the_attribute_metadata_is_inferred_from_the_proxy_types_assembly()
        {
            var fakedContext = new XrmFakedContext();
            fakedContext.ProxyTypesAssembly = Assembly.GetExecutingAssembly();

            var contact1 = new Entity("contact") { Id = Guid.NewGuid() }; contact1["fullname"] = "Contact 1"; contact1["firstname"] = "First 1";
            var contact2 = new Entity("contact") { Id = Guid.NewGuid() }; contact2["fullname"] = "Contact 2"; contact2["firstname"] = "First 2";

            fakedContext.Initialize(new List<Entity>() { contact1, contact2 });

            var guid = Guid.NewGuid();

            //Empty contecxt (no Initialize), but we should be able to query any typed entity without an entity not found exception

            var service = fakedContext.GetFakedOrganizationService();

            using (XrmServiceContext ctx = new XrmServiceContext(service))
            {
                var contact = (from c in ctx.CreateQuery<Contact>()
                               where c.FirstName.Equals("First 1")
                               select c).ToList();

                Assert.True(contact.Count == 1);
            }
        }
开发者ID:ccellar,项目名称:fake-xrm-easy,代码行数:25,代码来源:MetadataInferenceTests.cs


示例8: GetOneAccount

 public ProxyAccount GetOneAccount(Guid id)
 {
     CacheHelper.ClearCache();
     var xrm = new XrmServiceContext("Xrm");
     Account ac = xrm.AccountSet.Where(x => x.Id == id).FirstOrDefault();
     return ObjectConverter.SingleConvertToProxyAccount(ac);
 }
开发者ID:meanprogrammer,项目名称:DynamicsCRMProxy,代码行数:7,代码来源:AjaxAccountService.svc.cs


示例9: EntityViewDefinitionsGet

        public List<XrmSavedQueryDefinition> EntityViewDefinitionsGet(string entityName)
        {
            var xrmContext = new XrmServiceContext(_organizationService);

            var savedQueries = xrmContext.SavedQuerySet.Where(x => x.ReturnedTypeCode == entityName).ToList();

            var list = savedQueries.Select(MapSavedQueryToDefinition).ToList();

            return list;
        }
开发者ID:jaredrenken,项目名称:XrmViewDataRetrieval,代码行数:10,代码来源:DynamicsMetaDataService.cs


示例10: EntityViewDefinitionGet

        public XrmSavedQueryDefinition EntityViewDefinitionGet(Guid id)
        {
            var xrmService = new XrmServiceContext(_organizationService);

            var query = xrmService.SavedQuerySet.Single(x => x.SavedQueryId == id);

            var savedQueryDefinition = MapSavedQueryToDefinition(query);

            return savedQueryDefinition;
        }
开发者ID:jaredrenken,项目名称:XrmViewDataRetrieval,代码行数:10,代码来源:DynamicsMetaDataService.cs


示例11: Button1_Click

        protected void Button1_Click(object sender, EventArgs e)
        {
            var xrm = new XrmServiceContext("Xrm");

            //grab all contacts where the email address ends in @example.com
            var exampleContacts = xrm.OpportunitySet.ToList();

            ContactsGridView.DataSource = exampleContacts;
            ContactsGridView.DataBind();
        }
开发者ID:meanprogrammer,项目名称:ADBCRM2,代码行数:10,代码来源:WebForm_CodeBehindDataSource.aspx.cs


示例12: Page_Load

		protected void Page_Load(object sender, EventArgs e)
		{
			var xrm = new XrmServiceContext("Xrm");

			//grab all contacts where the email address ends in @example.com
			var exampleContacts = xrm.ContactSet
				.Where(c => c.EMailAddress1.EndsWith("@example.com"));

			ContactsGridView.DataSource = exampleContacts;
			ContactsGridView.DataBind();
		}
开发者ID:cesugden,项目名称:Scripts,代码行数:11,代码来源:WebForm_CodeBehindDataSource.aspx.cs


示例13: WriteExampleContacts

		/// <summary>
		/// Grab all contacts where the email address ends in @example.com
		/// </summary>
		private static void WriteExampleContacts(XrmServiceContext xrm)
		{
			var exampleContacts = xrm.ContactSet
				.Where(c => c.EMailAddress1.EndsWith("@example.com"));

			//write the example Contacts
			foreach (var contact in exampleContacts)
			{
				Console.WriteLine(contact.FullName);
			}
		}
开发者ID:cesugden,项目名称:Scripts,代码行数:14,代码来源:Program.cs


示例14: Page_Load

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                var xrm = new XrmServiceContext("Xrm");

                //grab all contacts where the email address ends in @example.com
                var opps = xrm.OpportunitySet.ToList();
                this.OpportunityDropdown.DataSource = opps;
                this.OpportunityDropdown.DataBind();
            }
        }
开发者ID:meanprogrammer,项目名称:ADBCRM2,代码行数:12,代码来源:Bhutan.aspx.cs


示例15: 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


示例16: 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


示例17: 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


示例18: When_using_proxy_types_assembly_the_entity_metadata_is_inferred_from_the_proxy_types_assembly

        public static void When_using_proxy_types_assembly_the_entity_metadata_is_inferred_from_the_proxy_types_assembly()
        {
            var fakedContext = new XrmFakedContext();
            fakedContext.ProxyTypesAssembly = Assembly.GetExecutingAssembly();
           
            //Empty contecxt (no Initialize), but we should be able to query any typed entity without an entity not found exception

            var service = fakedContext.GetFakedOrganizationService();

            using (XrmServiceContext ctx = new XrmServiceContext(service))
            {
                var contact = (from c in ctx.CreateQuery<Contact>()
                               where c.FirstName.Equals("Anything!")
                               select c).ToList();

                Assert.True(contact.Count == 0);
            }
        }
开发者ID:ccellar,项目名称:fake-xrm-easy,代码行数:18,代码来源:MetadataInferenceTests.cs


示例19: When_executing_a_linq_query_with_equals_between_2_strings_result_is_returned

        public void When_executing_a_linq_query_with_equals_between_2_strings_result_is_returned()
        {
            var fakedContext = new XrmFakedContext();
            var guid = Guid.NewGuid();
            fakedContext.Initialize(new List<Entity>() {
                new Contact() { Id = guid, FirstName = "Jordi" }
            });

            var service = fakedContext.GetFakedOrganizationService();

            using (XrmServiceContext ctx = new XrmServiceContext(service))
            {
                var contact = (from c in ctx.CreateQuery<Contact>()
                               where c.FirstName == "Jordi"
                               select c).FirstOrDefault();

                Assert.True(contact != null);
            }
        }
开发者ID:ccellar,项目名称:fake-xrm-easy,代码行数:19,代码来源:EqualityWithDifferentDataTypesTests.cs


示例20: When_doing_a_crm_linq_query_a_retrievemultiple_with_a_queryexpression_is_called

        public void When_doing_a_crm_linq_query_a_retrievemultiple_with_a_queryexpression_is_called()
        {
            var fakedContext = new XrmFakedContext();
            var guid = Guid.NewGuid();
            fakedContext.Initialize(new List<Entity>() {
                new Contact() { Id = guid, FirstName = "Jordi" }
            });

            var service = fakedContext.GetFakedOrganizationService();

            using (XrmServiceContext ctx = new XrmServiceContext(service))
            {
                var contact = (from c in ctx.CreateQuery<Contact>()
                               where c.FirstName.Equals("Jordi")
                               select c).FirstOrDefault();


            }
            A.CallTo(() => service.Execute(A<OrganizationRequest>.That.Matches(x => x is RetrieveMultipleRequest && ((RetrieveMultipleRequest)x).Query is QueryExpression))).MustHaveHappened();
        }
开发者ID:ccellar,项目名称:fake-xrm-easy,代码行数:20,代码来源:FakeContextTestLinqQueries.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# XtraForm类代码示例发布时间:2022-05-24
下一篇:
C# XrmFakedContext类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap