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


C# DynamicViewCompiler.MapDefinition方法代码示例

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


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

示例1: Convert_select_many_will_keep_doc_id

        public void Convert_select_many_will_keep_doc_id()
        {
            IndexDefinition indexDefinition = new IndexDefinition<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, new AbstractDynamicCompilationExtension[0])
                .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:bstrausser,项目名称:ravendb,代码行数:33,代码来源:LinqIndexesFromClient.cs

示例2: Can_compile_map_reudce_using_linq_methods

        public void Can_compile_map_reudce_using_linq_methods()
        {
            var viewGenerator = new DynamicViewCompiler("test", new IndexDefinition
            {
                Map = @"docs.Users
            .Select(user => new {Location = user.Location, Count = 1})",
                Reduce =
                    @"results
            .GroupBy(agg => agg.Location)
            .Select(g => new {Loction = g.Key, Count = g.Sum(x => x.Count}))"
            }).GenerateInstance();

            var results = viewGenerator.ReduceDefinition(viewGenerator.MapDefinition(new[]
            {
                GetDocumentFromString(
                @"
                {
                    '@metadata': {'Raven-Entity-Name': 'Users', '@id': 1},
                    'Location': 'Tel Aviv'
                }"),
                  GetDocumentFromString(
                @"
                {
                    '@metadata': {'Raven-Entity-Name': 'Users', '@id': 1},
                    'Location': 'Tel Aviv'
                }")
            })).Cast<object>().ToArray();

            var expected = new[]
            {
                "{ Loction = Tel Aviv, Count = 2 }",
            };

            for (var i = 0; i < results.Length; i++)
            {
                Assert.Equal(expected[i], results[i].ToString());
            }
        }
开发者ID:kenegozi,项目名称:ravendb,代码行数:38,代码来源:LinqTransformerCompilationTests.cs

示例3: Can_compile_map_using_linq_methods

		public void Can_compile_map_using_linq_methods()
		{
			var viewGenerator = new DynamicViewCompiler("test", new IndexDefinition
			{
				Map = @"docs.Users
	.Select(user => new {Location = user.Location, Count = 1})
	.Select(user => new {Location = user.Location})"
			}, new AbstractDynamicCompilationExtension[0]).GenerateInstance();


			var results = viewGenerator.MapDefinition(new[]
			{
				GetDocumentFromString(
				@"
                {
                    '@metadata': {'Raven-Entity-Name': 'Users', '@id': 1},
                    'Location': 'Tel Aviv'
                }")
			}).Cast<object>().ToArray();

			var expected = new[]
			{
				"{ Location = Tel Aviv, __document_id = 1 }",
			};

			for (var i = 0; i < results.Length; i++)
			{
				Assert.Equal(expected[i], results[i].ToString());
			}
		}
开发者ID:Rationalle,项目名称:ravendb,代码行数:30,代码来源:LinqTransformerCompilationTests.cs

示例4: LinqQueryWithStaticCallOnEnumerableIsCanBeCompiledAndRun

		public void LinqQueryWithStaticCallOnEnumerableIsCanBeCompiledAndRun()
		{
			var indexDefinition = new IndexDefinition<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, new AbstractDynamicCompilationExtension[] { }).
				GenerateInstance();

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

			var result = mapInstance.MapDefinition(new[] { dynamicObject }).ToList();
			Assert.Equal("{ Id = 0, CoAuthorUserID = 1, __document_id =  }", result[0].ToString());
			Assert.Equal("{ Id = 0, CoAuthorUserID = 2, __document_id =  }", result[1].ToString());
		}
开发者ID:ajaishankar,项目名称:ravendb,代码行数:28,代码来源:JsonSerializationBothWays.cs


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