RavenDb学习(八)高级特性上半部分
、事务支持
别的关系型数据库和RavenDb一起使用
using (var transaction = new TransactionScope())
{
BlogPost entity = session.Load<BlogPost>("blogs/1");
entity.Title = "Some new title";
session.SaveChanges(); // will create HTTP request
session.Delete(entity);
session.SaveChanges(); // will create HTTP request
transaction.Complete(); // will commit transaction
}
、文档元数据
Raven-Clr-Type - Records the CLR type, set and used by the JSON serialization/deserialization process in the Client API.
Raven-Entity-Name - Records the entity name, aka the name of the RavenDB collection this entity belongs to.
Non-Authoritive-Information - This boolean value will be set to true if the data received by the client has been modified by an uncommitted transaction. You can read more on it in the Advanced section.
Temp-Index-Score - When querying RavenDB, this value is the Lucene score of the entity for the query that was executed.
Raven-Read-Only - This document should be considered read only and not modified.
Last-Modified - The last modified time-stamp for the entity.
@etag - Every document in RavenDB has a corresponding e-tag (entity tag) stored as a sequential Guid. This e-tag is updated by RavenDB every time the document is changed.
@id - The entity id, as extracted from the entity itself.
获取最后修改时间的例子:
);
RavenJObject metadata = session.Advanced.GetMetadataFor(product);
// Get the last modified time stamp, which is known to be of type DateTime
DateTime collectionName = metadata.Value<DateTime>("Last-Modified");
返回所有表的表名的map函数:
from doc in docs
where doc["@metadata"]["Raven-Entity-Name"] != null
select new { Tag = doc["@metadata"]["Raven-Entity-Name"] };
//修改元数据
)通过session.Advanced.GetMetadatFor(entity) 获取元数据,然后修改并保存
)通过documentStore.RegisterListener(myStoreListener) 注册一个IDocumentStoreListener,当有session要进行保存的时候,它能修改元数据
、查询指定列
分页查询某个列
);
);
、动态列
public class Product
{
public string Id { get; set; }
public List<Attribute> Attributes { get; set; }
}
public class Attribute
{
public string Name { get; set; }
public string Value { get; set; }
}
上述例子,一个产品有很多个属性,属性的类型是不固定的,需要是dynamic的
//创建索引
public class Product_ByAttribute : AbstractIndexCreationTask<Product>
{
public Product_ByAttribute()
{
Map = products => from p in products
select new
{
_ = p.Attributes
.Select(attribute =>
CreateField(attribute.Name, attribute.Value, false, true))
};
}
}
//我们对值并不关注,只是希望调用CreateField方法,所以用_作为一种转换反射。
//查询
var products = session.Advanced.LuceneQuery<Product>("Product/ByAttribute")
.WhereEquals("Color", "Red")
.ToList();
这样子它不仅仅支持字符串,也支持数字等
、自定义序列化
当RavenDb收到一个POCO的时候,它会默认把它序列化为JSON格式的数据。
)忽略一个属性
public class Carrot
{
public string Id { get; set; }
public decimal Length { get; set; }
[JsonIgnore]
public decimal LengthInInch
{
get
{
/* some calculations */
return this.Length;
}
set
{
//...
}
}
}
)序列化的时候更换名字
public class Recipe
{
public string Id { get; set; }
[JsonProperty(PropertyName = "dishes")]
public IList<IVegetable> SideDishes { get; set; }
}
)允许自引用
//树形结构数据
[JsonObject(IsReference = true)]
public class Category
{
public string Id { get; set; }
public string Name { get; set; }
public Category Parent { get; set; }
public List<Category> Children { get; set; }
public Category()
{
this.Children = new List<Category>();
}
public void Add(Category category)
{
category.Parent = this;
this.Children.Add(category);
}
}
)自定义IContractResolver实现是序列
store.Conventions.JsonContractResolver = new DefaultContractResolver(shareCache: true)
{
DefaultMembersSearchFlags =
BindingFlags.Public | BindingFlags.Instance
};
RavenDb学习(八)高级特性上半部分的更多相关文章
- php面向对象编程学习之高级特性
前几天写了一篇关于php面向对象基础知识的博客,这两天看了php面向对象的高级特性,写出来记录一下吧,方便以后拿出来复习. 面向对象除了最基本的定义类之外,最主要就是因为面向的一些高级特性,运用这些高 ...
- Python学习札记(十八) 高级特性4 生成器
参考:生成器 Note 1.通过列表生成式,我们可以直接创建一个列表.但是,受到内存限制,列表容量肯定是有限的,且容易造成空间浪费.所以,如果列表元素可以按照某种算法推算出来,那我们可以在循环的过程中 ...
- nginx 学习八 高级数据结构之基数树ngx_radix_tree_t
1 nginx的基数树简单介绍 基数树是一种二叉查找树,它具备二叉查找树的全部长处:检索.插入.删除节点速度快,支持范围查找.支持遍历等. 在nginx中仅geo模块使用了基数树. nginx的基数树 ...
- Python学习之高级特性
切片 在Python基础篇里,我们知道Python的可序列对象可以通过索引号(下标)来引用对象元素,索引号可以由0开始从左向右依次获取,可以从-1开始由右向左获取.这种方法可以帮助我们依次获取我们想要 ...
- python学习之高级特性:
切片:对列表.元组.字符串.字典取中间的一部分,在C中一般是通过for循环拷贝/memcpy/strcat等操作.而python提供了更方便的切片操作符[m:n]:前闭后开,如果从0取m可以省略:如果 ...
- python切片、迭代、生成器、列表生成式等高级特性学习
python高级特性 1行代码能实现的功能,决不写5行代码.请始终牢记,代码越少,开发效率越高. 切片 当我们要取一个list中的前n各元素时,如果前n个少的话,我们还可以一个一个的取,但是若前n个元 ...
- 消息中间件——RabbitMQ(八)高级特性全在这里!(下)
前言 上一篇消息中间件--RabbitMQ(七)高级特性全在这里!(上)中我们介绍了消息如何保障100%的投递成功?,幂等性概念详解,在海量订单产生的业务高峰期,如何避免消息的重复消费的问题?,Con ...
- Python3学习(二)-递归函数、高级特性、切片
##import sys ##sys.setrecursionlimit(1000) ###关键字参数(**关键字参数名) ###与可变参数不同的是,关键字参数可以在调用函数时,传入带有参数名的参数, ...
- Spring框架学习[IoC容器高级特性]
1.通过前面4篇文章对Spring IoC容器的源码分析,我们已经基本上了解了Spring IoC容器对Bean定义资源的定位.读入和解析过程,同时也清楚了当用户通过getBean方法向IoC容器获取 ...
随机推荐
- spring配置上传文件大小
上传文件过大时,不会进入控制层,会直接抛出异常,提示上传文件过大,如下: org.apache.commons.fileupload.FileUploadBase$SizeLimitExceededE ...
- laravel5.7的redis配置,一直报错Class 'Predis\Client' not found
laravel5.7的redis配置,一直报错Class 'Predis\Client' not found 首先我检查了配置,和composer 都没有错,用原生的redis也可以正常连接和读写. ...
- MongoDB MapReduce 的示例。
// JavaScript source code db.runCommand({ mapreduce: "page", map: function Map() { emit( t ...
- java基础知识总结1
一. java开发工具 Editplus:Editplus与jdk的连接配置.如:javac(编译).java(运行).javap(查看字节码) a) 配置内容: i. javac(编译):參数为 - ...
- ace admin后台模板
http://ace.jeka.by/index.html 下载: http://www.daimajiayuan.com/plus/download.php?open=0&aid=18152 ...
- C语言:存取结构体成员的点运算符(.)和箭头运算符(->)的区别
转自:http://blog.csdn.net/taric_ma/article/details/7397362 一直以为这两个是没有什么区别的,可以相互替换,今天又翻了一下<C语言核心技术&g ...
- Spring、SpringMVC和Springboot的区别(网摘)
spring boot就是一个大框架里面包含了许许多多的东西,其中spring就是最核心的内容之一,当然就包含spring mvc. spring mvc 是只是spring 处理web层请求的一个模 ...
- 【小白的CFD之旅】22 好网格与坏网格
网格疏密网格形状其他的一些问题小白的总结郑重申明 网格的作用如此重要,以至于小白纠结了很久.小白知道网格划分过程很大程度上受制于计算资源的限制,但小白还是不太明白,如果计算资源非常充足,不用顾忌资源限 ...
- OpenStack的基本概念与架构图
https://blog.csdn.net/zjluobing/article/details/51489325 OpenStack项目是一个开源的云计算平台,旨在实现很简单,大规模可伸缩,功能丰富. ...
- 每日英语:American Cities May Have Hit 'Peak Office'
Despite some hype and a few regional exceptions, the construction of office towers and suburban offi ...