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


C# IndexDefinitionBuilder类代码示例

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


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

示例1: LinqQueryWithStaticCallOnEnumerableIsCanBeCompiledAndRun

		public void LinqQueryWithStaticCallOnEnumerableIsCanBeCompiledAndRun()
		{
			var indexDefinition = new IndexDefinitionBuilder<Page>
			{
				Map = pages => from p in pages
							   from coAuthor in p.CoAuthors.DefaultIfEmpty()
							   select new
							   {
								   p.Id,
								   CoAuthorUserID = coAuthor != null ? coAuthor.UserId : -1
							   }
			}.ToIndexDefinition(new DocumentConvention());

			var mapInstance = new DynamicViewCompiler("testView",
													  indexDefinition, ".").
				GenerateInstance();

			var conventions = new DocumentConvention();
			var o = RavenJObject.FromObject(page,conventions.CreateSerializer());
			o["@metadata"] = new RavenJObject {{"Raven-Entity-Name", "Pages"}};
			dynamic dynamicObject = new DynamicJsonObject(o);

			var result = mapInstance.MapDefinitions[0](new[] { dynamicObject }).ToList<object>();
			Assert.Equal("{ Id = 0, CoAuthorUserID = 1, __document_id =  }", result[0].ToString());
			Assert.Equal("{ Id = 0, CoAuthorUserID = 2, __document_id =  }", result[1].ToString());
		}
开发者ID:925coder,项目名称:ravendb,代码行数:26,代码来源:DocumentToJsonAndBackTest.cs

示例2: LinqQueryWithIndexIsCaseInsensitive

		public void LinqQueryWithIndexIsCaseInsensitive()
		{
			using (var store = this.NewDocumentStore())
			{
				var definition = new IndexDefinitionBuilder<Company>
				{
					Map = docs => from doc in docs
								  select new
								  {
									  doc.Name
								  }
				}.ToIndexDefinition(store.Conventions);
				store.DatabaseCommands.PutIndex("CompanyByName",
												definition);

				using (var session = store.OpenSession())
				{
					session.Store(new Company { Name = "Google" });
					session.Store(new Company
					{
						Name =
							"HibernatingRhinos"
					});
					session.SaveChanges();

					var company =
						session.Query<Company>("CompanyByName")
							.Customize(x=>x.WaitForNonStaleResults())
							.Where(x=>x.Name == "Google")
							.FirstOrDefault();

					Assert.NotNull(company);
				}
			}
		}
开发者ID:JPT123,项目名称:ravendb,代码行数:35,代码来源:QueryingFromIndex.cs

示例3: Convert_select_many_will_keep_doc_id

        public void Convert_select_many_will_keep_doc_id()
        {
            IndexDefinition indexDefinition = new IndexDefinitionBuilder<Order>
            {
                Map = orders => from order in orders
                                from line in order.OrderLines
                                select new { line.ProductId }
            }.ToIndexDefinition(new DocumentConvention());
			var generator = new DynamicViewCompiler("test", indexDefinition,  ".")
                .GenerateInstance();


            var results = generator.MapDefinition(new[]
			{
				GetDocumentFromString(
				@"
                {
                    '@metadata': {'Raven-Entity-Name': 'Orders', '@id': 1},
                    'OrderLines': [{'ProductId': 2}, {'ProductId': 3}]
                }"),
				  GetDocumentFromString(
				@"
                {
                    '@metadata': {'Raven-Entity-Name': 'Orders', '@id': 2},
                    'OrderLines': [{'ProductId': 5}, {'ProductId': 4}]
                }")
			}).Cast<object>().ToArray();

            foreach (var result in results)
            {
                Assert.NotNull(TypeDescriptor.GetProperties(result).Find("__document_id", true));
            }
        }
开发者ID:nzdunic,项目名称:ravendb,代码行数:33,代码来源:LinqIndexesFromClient.cs

示例4: CanDefineHierarchicalIndexOnTheClient_WithLinq

		public void CanDefineHierarchicalIndexOnTheClient_WithLinq()
		{
			var indexDefinition = new IndexDefinitionBuilder<Person>
			{
				Map = people => from p in people
								from c in p.Hierarchy(x=>x.Children)
								select c.Name
			}.ToIndexDefinition(new DocumentConvention());

			Assert.Equal("docs.People\r\n\t.SelectMany(p => Hierarchy(p, \"Children\"), (p, c) => c.Name)", indexDefinition.Map);
		}
开发者ID:neiz,项目名称:ravendb,代码行数:11,代码来源:HierarchyFromClient.cs

示例5: WillNotForgetCastToNullableDateTime

		public void WillNotForgetCastToNullableDateTime()
		{
			var indexDefinition = new IndexDefinitionBuilder<DanTurner.Person>
			{
				Map = persons => from p in persons select new {DateTime = (DateTime?) null}
			}.ToIndexDefinition(new DocumentConvention());

			const string expected = @"docs.People.Select(p => new {
    DateTime = ((DateTime ? ) null)
})";
			Assert.Equal(expected, indexDefinition.Map);
		}
开发者ID:925coder,项目名称:ravendb,代码行数:12,代码来源:RavenDB_483.cs

示例6: WillNotForgetCastToNullableDateTime

        public void WillNotForgetCastToNullableDateTime()
        {
            var indexDefinition = new IndexDefinitionBuilder<Person>()
            {
                Map = persons => from p in persons select new {DateTime = (DateTime?) null}
            }.ToIndexDefinition(new DocumentConvention{PrettifyGeneratedLinqExpressions = false});

            const string expected = @"docs.People.Select(p => new {
    DateTime = ((DateTime ? ) null)
})";
            Assert.Equal(expected, indexDefinition.Map);
        }
开发者ID:j2jensen,项目名称:ravendb,代码行数:12,代码来源:RavenDB_483.cs

示例7: CanCompileComplexQuery

		public void CanCompileComplexQuery()
		{
			var indexDefinition = new IndexDefinitionBuilder<Person>()
			{
				Map = people => from person in people
				                from role in person.Roles
				                where role == "Student"
				                select new { role }
			}.ToIndexDefinition(new DocumentConvention());

			new DynamicViewCompiler("test", indexDefinition,  ".")
                .GenerateInstance();
		}
开发者ID:nzdunic,项目名称:ravendb,代码行数:13,代码来源:LinqIndexesFromClient.cs

示例8: CanDefineHierarchicalIndexOnTheClient_WithLinq2

		public void CanDefineHierarchicalIndexOnTheClient_WithLinq2()
		{
			var indexDefinition = new IndexDefinitionBuilder<Container>
			{
				Map = containers => from c in containers
									select new
									{
										Names = c.Hierarchy(x => x.Containers).Select(x => x.Name)
									}
			}.ToIndexDefinition(new DocumentConvention());

			Assert.Equal("docs.Containers\r\n\t.Select(c => new {Names = Hierarchy(c, \"Containers\")\r\n\t.Select(x => x.Name)})", indexDefinition.Map);
		}
开发者ID:neiz,项目名称:ravendb,代码行数:13,代码来源:HierarchyFromClient.cs

示例9: LinqQueryWithStaticCallOnEnumerableIsTranslatedToExtensionMethod

		public void LinqQueryWithStaticCallOnEnumerableIsTranslatedToExtensionMethod()
		{
			var indexDefinition = new IndexDefinitionBuilder<Page>
			{
				Map = pages => from p in pages
							   from coAuthor in p.CoAuthors.DefaultIfEmpty()
							   select new
							   {
								   p.Id,
								   CoAuthorUserID = coAuthor != null ? coAuthor.UserId : -1
							   }
			}.ToIndexDefinition(new DocumentConvention());
			Assert.Contains("p.CoAuthors.DefaultIfEmpty()", indexDefinition.Map);
		}
开发者ID:925coder,项目名称:ravendb,代码行数:14,代码来源:DocumentToJsonAndBackTest.cs

示例10: Can_define_index_with_WhereEntityIs

		public void Can_define_index_with_WhereEntityIs()
		{
			var idxBuilder = new IndexDefinitionBuilder<object>
			{
				Map =
					docs =>
					from course in (IEnumerable<Course>) docs
					select new {course.Id, course},

				TransformResults =
					(database, docs) =>
					from course in (IEnumerable<Course>) docs
					select new
					{
						item = course.Name,
						id = course.Id,
						iconCls = "course",
						leaf = false,
						expanded = true,
						children =
						from unit in course.Syllabus
						select new
						{
							item = unit.Name,
							id = unit.Name,
							iconCls = "unit",
							leaf = false,
							expanded = true,
							children =
							from notebook in unit.Notebooks
							select new
							{
								item = notebook.Name,
								id = notebook.Id,
								courseId = course.Id,
								iconCls = "notebook",
								type = notebook.Type,
								leaf = true,
							}
						}
					}
			};

			using(var store = NewDocumentStore())
			{
				var indexDefinition = idxBuilder.ToIndexDefinition(store.Conventions);
				store.DatabaseCommands.PutIndex("test", indexDefinition);
			}
		}
开发者ID:ReginaBricker,项目名称:ravendb,代码行数:49,代码来源:JBA.cs

示例11: Id_on_member_should_not_be_converted_to_document_id

		public void Id_on_member_should_not_be_converted_to_document_id()
		{
			var generated = new IndexDefinitionBuilder<SubCategory>
			{
				Map = subs => from subCategory in subs
							  select new
							  {
								  CategoryId = subCategory.Id,
								  SubCategoryId = subCategory.Parent.Id
							  }
			}.ToIndexDefinition(new DocumentConvention());
			
			Assert.Contains("CategoryId = subCategory.__document_id", generated.Map);
			Assert.Contains("SubCategoryId = subCategory.Parent.Id", generated.Map);
		}
开发者ID:925coder,项目名称:ravendb,代码行数:15,代码来源:TranslatingLinqQueryUsingNestedId.cs

示例12: Can_project_Id_from_transformResults

		public void Can_project_Id_from_transformResults()
		{
			using (GetNewServer())
			using (var store = new DocumentStore {Url = "http://localhost:8079"})
			{
				store.Initialize();
				store.Conventions.FindIdentityProperty = (x => x.Name == "Id");
				var indexDefinition = new IndexDefinitionBuilder<Shipment1, Shipment1>()
				                      	{
				                      		Map = docs => from doc in docs
				                      		              select new
				                      		                     	{
				                      		                     		doc.Id
				                      		                     	},
				                      		TransformResults = (database, results) => from doc in results
				                      		                                          select new
				                      		                                                 	{
				                      		                                                 		Id = doc.Id,
				                      		                                                 		Name = doc.Name
				                      		                                                 	}

				                      	}.ToIndexDefinition(store.Conventions);
				store.DatabaseCommands.PutIndex(
					"AmazingIndex1",
					indexDefinition);


				using (var session = store.OpenSession())
				{
					session.Store(new Shipment1()
					              	{
					              		Id = "shipment1",
					              		Name = "Some shipment"
					              	});
					session.SaveChanges();

					var shipment = session.Query<Shipment1>("AmazingIndex1")
						.Customize(x => x.WaitForNonStaleResults())
						.Select(x => new Shipment1
						             	{
						             		Id = x.Id,
						             		Name = x.Name
						             	}).Take(1).SingleOrDefault();

					Assert.NotNull(shipment.Id);
				}
			}
		}
开发者ID:925coder,项目名称:ravendb,代码行数:48,代码来源:spokeypokey.cs

示例13: Can_define_index_with_WhereEntityIs

		public void Can_define_index_with_WhereEntityIs()
		{
			var idxBuilder = new IndexDefinitionBuilder<object>("test")
			{
				Map =
					docs =>
					from course in (IEnumerable<Course>) docs
					select new {course.Id, course},
			};

			using(var store = NewDocumentStore())
			{
				var indexDefinition = idxBuilder.ToIndexDefinition(store.Conventions);
				store.DatabaseCommands.PutIndex("test", indexDefinition);
			}
		}
开发者ID:GorelH,项目名称:ravendb,代码行数:16,代码来源:JBA.cs

示例14: LinqQueryWithStaticCallOnEnumerableIsTranslatedToExtensionMethod

		public void LinqQueryWithStaticCallOnEnumerableIsTranslatedToExtensionMethod()
		{
			var indexDefinition = new IndexDefinitionBuilder<Page>
			{
				Map = pages => from p in pages
							   from coAuthor in Enumerable.DefaultIfEmpty(p.CoAuthors)
							   select new
							   {
								   p.Id,
								   CoAuthorUserID = coAuthor != null ? coAuthor.UserId : -1
							   }
			}.ToIndexDefinition(new DocumentConvention());
			var expectedMapTranslation =
				@"docs.Pages
	.SelectMany(p => p.CoAuthors.DefaultIfEmpty(), (p, coAuthor) => new {Id = p.Id, CoAuthorUserID = coAuthor != null ? coAuthor.UserId : -1})";
			Assert.Equal(expectedMapTranslation, indexDefinition.Map);
		}
开发者ID:nhsevidence,项目名称:ravendb,代码行数:17,代码来源:DocumentToJsonAndBackTest.cs

示例15: CanRunSpatialQueriesInMemory

		public void CanRunSpatialQueriesInMemory()
		{
			var documentStore = new EmbeddableDocumentStore { RunInMemory = true };
			documentStore.Initialize();
			var def = new IndexDefinitionBuilder<Listing>
			{
				Map = listings => from listingItem in listings
								  select new
								  {
									  listingItem.ClassCodes,
									  listingItem.Latitude,
									  listingItem.Longitude,
									  _ = SpatialIndex.Generate(listingItem.Latitude, listingItem.Longitude)
								  }
			};
			documentStore.DatabaseCommands.PutIndex("RadiusClassifiedSearch", def);
		}
开发者ID:JPT123,项目名称:ravendb,代码行数:17,代码来源:SpatialQueries.cs


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