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

C# IndexDefinitionBuilder类代码示例

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

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



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


示例16: DefaultIndexingBehaviourAllowStartsWith

		public void DefaultIndexingBehaviourAllowStartsWith()
		{
			using (var store = this.NewDocumentStore())
			{
				var index = new IndexDefinitionBuilder<Blog, BlogTagItem>()
				{
					Map = docs => from doc in docs
								  from tag in doc.Tags
								  select new
								  {
									  tag.Name,
									  Count = 1
								  },
					Reduce = results => from result in results
										group result by result.Name into g
										select new
										{
											Name = g.Key,
											Count = g.Count()
										}

				}.ToIndexDefinition(store.Conventions);

				store.DatabaseCommands.PutIndex("TagInfo", index);


				using (var session = store.OpenSession())
				{
					var newBlog = new Blog()
					{
						Tags = new[]{
							 new BlogTag() { Name = "SuperCallaFragalisticExpealadocious" }
						}
					};
					session.Store(newBlog);
					session.SaveChanges();

					var result = session.Query<BlogTagItem>("TagInfo")
						.Customize(x => x.WaitForNonStaleResults())
						.Where(x => x.Name.StartsWith("Su"))
						.FirstOrDefault();

					Assert.NotNull(result);
				}
			}
		}
开发者ID:nhsevidence,项目名称:ravendb,代码行数:46,代码来源:UsingStartsWith.cs


示例17: CanProjectIdFromTransformResults

		public void CanProjectIdFromTransformResults()
		{
			using (var store = NewDocumentStore())
			{
				var indexDefinition = new IndexDefinitionBuilder<Shipment, Shipment>()
				                      	{
				                      		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(
					"AmazingIndex",
					indexDefinition);


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

					var shipment = session.Query<Shipment>("AmazingIndex")
						.Customize(x=>x.WaitForNonStaleResults())
						.Select(x => new Shipment
						{
							Id = x.Id,
							Name = x.Name
						}).Take(1).SingleOrDefault();
					
					Assert.NotNull(shipment.Id);
				}
			}
		}
开发者ID:ReginaBricker,项目名称:ravendb,代码行数:45,代码来源:CanProjectIdFromDocumentInQueries.cs


示例18: with_index_and_some_entities

		public void with_index_and_some_entities(Action<IDocumentSession> action)
		{
			using (var store = NewDocumentStore(requestedStorage: "esent"))
			{
				var indexDefinition = new IndexDefinitionBuilder<Entity, EntityCount>()
				{
					Map = docs => docs.Select(doc => new { Name = doc.Name, NormalizedName = doc.Name, Count = 1 }),
					Reduce = docs => from doc in docs
									 group doc by new { doc.Name } into g
									 select new { Name = g.Key.Name, NormalizedName = g.Key.Name, Count = g.Sum(c => c.Count) },
					Indexes =
						{
							{e => e.Name, FieldIndexing.NotAnalyzed }
						}
				}.ToIndexDefinition(store.Conventions);

				indexDefinition.Analyzers = new Dictionary<string, string>()
				{
					{"NormalizedName", typeof (CustomAnalyzer).AssemblyQualifiedName}
				};

				store.DatabaseCommands.PutIndex("someIndex", indexDefinition);

				using (var session = store.OpenSession())
				{
					session.Store(new Entity() { Name = entityName });
					session.Store(new Entity() { Name = entityName });
					session.Store(new Entity() { Name = entityName });
					session.Store(new Entity() { Name = entityName });
					session.Store(new Entity() { Name = "someOtherName1" });
					session.Store(new Entity() { Name = "someOtherName2" });
					session.Store(new Entity() { Name = "someOtherName3" });
					session.SaveChanges();
				}
				
				// This wait should update the index with all changes...
				WaitForIndex(store, "someIndex");

				using (var session2 = store.OpenSession())
				{
					action(session2);
				}
			}
		}
开发者ID:925coder,项目名称:ravendb,代码行数:44,代码来源:UsingCustomLuceneAnalyzer.cs


示例19: get_index_names

        public void get_index_names()
        {
            using (IDocumentStore store = NewDocumentStore())
            {
                for (int i = 1; i <= 10; i++)
                {
                    using (var session = store.OpenSession())
                    {
                        session.Store(new Entity()
                        {
                            OrganizationId = 1,
                            HistoryCode = 2,
                            CaseId = 3
                        });
                        session.SaveChanges();
                    }
                }

                for (int i = 1; i <= 30; i++)
                {
                    IndexDefinitionBuilder<Entity> builder = new IndexDefinitionBuilder<Entity>
                    {
                        Map = entities => from e in entities
                            select new
                            {
                                Id = e.OrganizationId,
                                Code = e.HistoryCode,
                                Case = e.CaseId
                            }
                    };

                    store.DatabaseCommands.PutIndex("TestIndex/Numer"+i , builder.ToIndexDefinition(store.Conventions));
                }

                WaitForIndexing(store);

                using (var session = store.OpenSession())
                {
                    Task.Run(() => LoopResetIndex(session)).Wait();
                }
            }
        }
开发者ID:j2jensen,项目名称:ravendb,代码行数:42,代码来源:RavenDB-4011.cs


示例20: 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());
            var original = new IndexDefinition
            {
                Map =
                    @"docs.SubCategories
	.Select(subCategory => new {CategoryId = subCategory.__document_id, SubCategoryId = subCategory.Parent.Id})"
            };

            Assert.Equal(original.Map, generated.Map);
        }
开发者ID:nzdunic,项目名称:ravendb,代码行数:20,代码来源:TranslatingLinqQueryUsingNestedId.cs



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C# IndexDeletionPolicy类代码示例发布时间:2022-05-24
下一篇:
C# IndexDefinition类代码示例发布时间: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