博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
RavenDb学习(七) 异步工作以及维度查询
阅读量:6337 次
发布时间:2019-06-22

本文共 3922 字,大约阅读时间需要 13 分钟。

1、异步执行var entity = new Company {Name = "Async Company #2", Id = "companies/2"};using (var session = documentStore.OpenAsyncSession()){    var company = await session.LoadAsync
(1); // loading an entity asynchronously await session.StoreAsync(entity); // in-memory operations are committed asynchronously when calling SaveChangesAsync await session.SaveChangesAsync(); // returns a task that completes asynchronously var query = session.Query
() .Where(x => x.Name == "Async Company #1") .ToListAsync(); // returns a task that will execute the query}2、维度查询假设我们有一个这样的文档: { DateOfListing: "2000-09-01T00:00:00.0000000+01:00" Manufacturer: "Jessops" Model: "blah" Cost: 717.502206059872 Zoom: 9 Megapixels: 10.4508949012733 ImageStabiliser: false}1)建立基于制造厂商,成本和像素的维度var _facets = new List
{ new Facet { Name = "Manufacturer" }, new Facet { Name = "Cost_Range", Mode = FacetMode.Ranges, Ranges = { "[NULL TO Dx200.0]", "[Dx200.0 TO Dx400.0]", "[Dx400.0 TO Dx600.0]", "[Dx600.0 TO Dx800.0]", "[Dx800.0 TO NULL]", } }, new Facet { Name = "Megapixels_Range", Mode = FacetMode.Ranges, Ranges = { "[NULL TO Dx3.0]", "[Dx3.0 TO Dx7.0]", "[Dx7.0 TO Dx10.0]", "[Dx10.0 TO NULL]", } } };成本字段范围Cost <= 200.0200.0 <= Cost <= 400.0400.0 <= Cost <= 600.0600.0 <= Cost <= 800.0Cost >= 800.0像素字段范围Megapixels <= 3.03.0 <= Megapixels <= 7.07.0 <= Megapixels <= 10.0Megapixels >= 10.0//保存session.Store(new FacetSetup { Id = "facets/CameraFacets", Facets = _facets });2、创建索引store.DatabaseCommands.PutIndex("CameraCost", new IndexDefinition { Map = @"from camera in docs select new { camera.Manufacturer, camera.Model, camera.Cost, camera.DateOfListing, camera.Megapixels }" });3、查询var facetResults = session.Query
("CameraCost") .Where(x => x.Cost >= 100 && x.Cost <= 300) .ToFacets("facets/CameraFacets");通过通过这个网址查询:http://localhost:8080/facets/CameraCost?facetDoc=facets/CameraFacets&query=Cost_Range:[Dx100 TO Dx300.0]结果如下: { Manufacturer: [ { Range: 'canon', Count: 42 }, { Range: 'jessops', Count: 50 }, { Range: 'nikon', Count: 46 }, { Range: 'phillips', Count: 44 }, { Range: 'sony', Count: 35 } ], Cost_Range: [ { Range: '[NULL TO Dx200.0]', Count: 115 }, { Range: '[Dx200.0 TO Dx400.0]', Count: 102 } ], Megapixels_Range: [ { Range: '[NULL TO Dx3.0]', Count: 42 }, { Range: '[Dx3.0 TO Dx7.0]', Count: 79 }, { Range: '[Dx7.0 TO Dx10.0]', Count: 82 }, { Range: '[Dx10.0 TO NULL]', Count: 14 } ]}

 

转载地址:http://ufaoa.baihongyu.com/

你可能感兴趣的文章
rSync服务器实现不同平台下备份数据
查看>>
检查服务器各类信息脚本
查看>>
linux用户及权限管理
查看>>
Docker配置网络
查看>>
yum安装cacti
查看>>
Zabbix通过Orabbix监控Oracle
查看>>
linux双线双网卡双IP双网关设置方法
查看>>
免费站长工具大全
查看>>
Android Studio第十期 - 招商银行两种支付方式
查看>>
详细解读Jquery各Ajax函数:$.get(),$.post(),$.ajax(),$.getJSON()
查看>>
DHCP在企业网中的应用
查看>>
2008的共享服务器搭建
查看>>
Linux常用的命令
查看>>
已经不再更新新浪、网易及CSDN博客了!
查看>>
虚拟机克隆后修改mac地址和ip地址
查看>>
解决数据库乱码问题【转】
查看>>
注册表操作类【原】
查看>>
清远市第一中学大学城网
查看>>
环回接口(loopback interface)的新认识
查看>>
LINQ之路13:LINQ Operators之连接(Joining)
查看>>