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


C# XrmServiceContext类代码示例

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


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


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