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


C# XrmServiceContext.CreateQuery方法代码示例

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


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

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

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

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

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

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

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

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

示例9: When_executing_a_linq_query_with_equals_between_2_boolean_managed_properties_result_is_returned

        public void When_executing_a_linq_query_with_equals_between_2_boolean_managed_properties_result_is_returned()
        {
            var fakedContext = new XrmFakedContext();
            var guid = Guid.NewGuid();
            fakedContext.Initialize(new List<Entity>() {
                new Report() { Id = guid, IsCustomizable = new BooleanManagedProperty(true) },
                new Report() { Id = Guid.NewGuid()}  //To test also nulls
            });

            var service = fakedContext.GetFakedOrganizationService();

            using (XrmServiceContext ctx = new XrmServiceContext(service))
            {
                var contact = (from c in ctx.CreateQuery<Report>()
                               where c.IsCustomizable.Value == true
                               select c).ToList();

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

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

示例11: When_executing_a_linq_query_with_equals_between_2_booleans_result_is_returned

        public void When_executing_a_linq_query_with_equals_between_2_booleans_result_is_returned()
        {
            var fakedContext = new XrmFakedContext();
            var guid = Guid.NewGuid();
            fakedContext.Initialize(new List<Entity>() {
                new Contact() { Id = guid, IsBackofficeCustomer = true},
                new Contact() { Id = Guid.NewGuid()}  //To test also nulls
            });

            var service = fakedContext.GetFakedOrganizationService();

            using (XrmServiceContext ctx = new XrmServiceContext(service))
            {
                var contact = (from c in ctx.CreateQuery<Contact>()
                               where c.IsBackofficeCustomer != null && c.IsBackofficeCustomer.Value == true
                               where c.IsBackofficeCustomer.Value
                               select c).ToList();

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

示例12: XrmFakedContext

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

            var account = new Account() { Id = Guid.NewGuid() };
            account["statecode"] = null;

            context.Initialize(new List<Entity>()
            {
                account
            });

            using (var ctx = new XrmServiceContext(service))
            {
                var a = (from acc in ctx.CreateQuery<Account>()
                         select acc).FirstOrDefault();

                Assert.Equal(0, a.FormattedValues.Count);
                Assert.False(a.FormattedValues.Contains("statecode"));
            }
        }
开发者ID:ccellar,项目名称:fake-xrm-easy,代码行数:22,代码来源:FakeContextTestFormattedValues.cs

示例13: XrmFakedContext

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

            var contactId = Guid.NewGuid();

            fakedContext.Initialize(new List<Entity>() {
                new Contact() { Id = contactId, StatusCode = new OptionSetValue(1) },
                new Contact() { Id = Guid.NewGuid(), StatusCode = null },
            });

            var service = fakedContext.GetFakedOrganizationService();

            using (XrmServiceContext ctx = new XrmServiceContext(service))
            {
                var matches = (from c in ctx.CreateQuery<Contact>()
                               where c.StatusCode == null
                               select c).ToList();

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

示例14: When_doing_a_crm_linq_query_with_a_less_than_or_equal_operator_record_is_returned

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

            fakedContext.Initialize(new List<Entity>() {
                new Contact() { Id = guid1, NumberOfChildren = 3 },
                new Contact() { Id = guid2, NumberOfChildren = 1 },
                new Contact() { Id = guid3, NumberOfChildren = 2 }
            });

            var service = fakedContext.GetFakedOrganizationService();

            using (XrmServiceContext ctx = new XrmServiceContext(service))
            {
                var matches = (from c in ctx.CreateQuery<Contact>()
                               where c.NumberOfChildren.Value <= 3
                               select c).ToList();

                Assert.True(matches.Count == 3);
            }
        }
开发者ID:ccellar,项目名称:fake-xrm-easy,代码行数:24,代码来源:FakeContextTestLinqQueries.cs

示例15: When_doing_a_crm_linq_query_with_a_not_null_operator_record_is_returned

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

            fakedContext.Initialize(new List<Entity>() {
                new Contact() { Id = guid1, FirstName = null },
                new Contact() { Id = guid2 }, //FirstName attribute omitted
                new Contact() { Id = guid3, FirstName = "Other" }
            });

            var service = fakedContext.GetFakedOrganizationService();

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

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


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