コード例 #1
0
ファイル: Querying.cs プロジェクト: cocytus/ravendb
        public void CanDoSimpleQueryOnDatabase()
        {
            const string indexName = "CompaniesByName";
            using (var store = GetDocumentStore())
            {
                var contact1 = new Contact { FirstName = "Expression Name" };
                var contact2 = new Contact { FirstName = "Expression First Name" };
                var contact3 = new Contact { FirstName = "First Name" };

                store.DatabaseCommands.Put("contacts/1", null, RavenJObject.FromObject(contact1), new RavenJObject { { "Raven-Entity-Name", "Contacts" } });
                store.DatabaseCommands.Put("contacts/2", null, RavenJObject.FromObject(contact2), new RavenJObject { { "Raven-Entity-Name", "Contacts" } });
                store.DatabaseCommands.Put("contacts/3", null, RavenJObject.FromObject(contact3), new RavenJObject { { "Raven-Entity-Name", "Contacts" } });

                store.DatabaseCommands.PutIndex(indexName, new IndexDefinition()
				{
					Map = "from contact in docs.Contacts select new { contact.FirstName }"
				}, false);
                WaitForIndexing(store);

                var companies = store.DatabaseCommands.Query(indexName, new IndexQuery { Query = "" }, null);
                Assert.Equal(3, companies.TotalResults);
                Assert.Equal("Expression Name", companies.Results[0].Value<string>("FirstName"));
                Assert.Equal("Expression First Name", companies.Results[1].Value<string>("FirstName"));
                Assert.Equal("First Name", companies.Results[2].Value<string>("FirstName"));
            }
        }
コード例 #2
0
ファイル: Filtering.cs プロジェクト: j2jensen/ravendb
        public void BasicFiltering()
        {
            using (var store = GetDocumentStore())
            {
                using (var session = store.OpenSession())
                {
                    var contact1 = new Contact { FirstName = "First Expression Name" };
                    var contact2 = new Contact { FirstName = "Expression First Name" };
                    var contact3 = new Contact { FirstName = "First Name" };
                    session.Store(contact1);
                    session.Store(contact2);
                    session.Store(contact3);
                    session.Store(new Company { Name = "Company1", Contacts = new List<Contact> { contact1, contact2, contact3 } });
                    session.Store(new Company { Name = "Company2", Contacts = new List<Contact> { contact1, contact2 } });
                    session.Store(new Company { Name = "Company3", Contacts = new List<Contact> { contact3 } });
                    session.SaveChanges();

                    var companies = session.Query<Company>()
                        .Where(x => x.Contacts.Any(contact => contact.FirstName == "First Name"))
                        .ToArray();
                    Assert.Equal(2, companies.Length);
                    Assert.Equal(3, companies[0].Contacts.Count);
                    Assert.Equal(1, companies[1].Contacts.Count);

                    companies = session.Query<Company>()
                        .Where(c => c.Name.In(new[] { "Company1", "Company3" }))
                        .ToArray();
                    Assert.Equal(2, companies.Length);
                    Assert.Equal("Company1", companies[0].Name);
                    Assert.Equal("Company3", companies[1].Name);
                }
            }
        }
コード例 #3
0
ファイル: StaticIndexes.cs プロジェクト: WimVergouwe/ravendb
        public void CreateAndQuerySimpleMapReduceIndexWithMetadataForCall()
        {
            using (var store = GetDocumentStore())
            {
                new Companies_CompanyByType().Execute(store);
                WaitForIndexing(store);

                using (var session = store.OpenSession())
                {
                    var contact1 = new Contact { FirstName = "FirstName1" };
                    var contact2 = new Contact { FirstName = "FirstName2" };
                    var contact3 = new Contact { FirstName = "FirstName3" };
                    session.SaveChanges();

                    session.Store(new Company 
                        {
                            Type = Company.CompanyType.Public, 
                            Contacts = new List<Contact> {contact1, contact2, contact3}
                        });
                    session.Store(new Company 
                        {
                            Type = Company.CompanyType.Public, 
                            Contacts = new List<Contact> {contact3}
                        });
                    session.Store(new Company 
                        {
                            Type = Company.CompanyType.Public, 
                            Contacts = new List<Contact> {contact1, contact2}
                        });
                    session.Store(new Company 
                        {
                            Type = Company.CompanyType.Private, 
                            Contacts = new List<Contact> {contact1, contact2}
                        });
                    session.Store(new Company 
                        {
                            Type = Company.CompanyType.Private, 
                            Contacts = new List<Contact> {contact1, contact2, contact3}
                        });
                    session.SaveChanges();
                    WaitForIndexing(store);

                    Companies_CompanyByType.ReduceResult[] companies = session.Query<Companies_CompanyByType.ReduceResult, Companies_CompanyByType>()
                        .OrderBy(x => x.Type)
                        .ToArray();
                    Assert.Equal(2, companies.Length);
                    Assert.Equal(Company.CompanyType.Private, companies[0].Type);
                    Assert.Equal(5, companies[0].ContactsCount);
                    Assert.NotNull(companies[0].LastModified);
                    Assert.Equal(Company.CompanyType.Public, companies[1].Type);
                    Assert.Equal(6, companies[1].ContactsCount);
                    Assert.NotNull(companies[1].LastModified);
                }
            }
        }