本文整理汇总了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));
}
}
示例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());
}
}
示例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());
}
}
示例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());
}