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容器获取 ...
随机推荐
- java类中serialversionuid 作用 是什么?举个例子说明(转)
serialVersionUID适用于Java的序列化机制.简单来说,Java的序列化机制是通过判断类的serialVersionUID来验证版本一致性的.在进行反序列化时,JVM会把传来的字节流中的 ...
- Linux 系统结构详解【转】
Linux系统一般有4个主要部分: 内核.shell.文件系统和应用程序.内核.shell和文件系统一起形成了基本的操作系统结构,它们使得用户可以运行程序.管理文件并使用系统.部分层次结构如图1-1所 ...
- java https 请求
http://li3huo.com/index.php/2009/09/https-certificates-are-ignoring-the-right-java-http-client/
- elasticsearch 索引延迟 一致性问题等
https://www.elastic.co/guide/en/elasticsearch/guide/current/near-real-time.html https://www.elastic. ...
- MySQL开发索引创建规范
1. [强制]业务上具有唯一特性的字段,即使是多个字段的组合,也必须建成唯一索引. 说明:不要以为唯一索引影响了insert速度,这个速度损耗可以忽略,但提高查找速度是明显的:另外,即使在应用层做了非 ...
- 采用Oracle的dbms_obfuscation_toolkit的加密
create or replace function MD5 (vpassword in varchar2) return varchar2 is retval varchar2(32); begin ...
- 【Android】json格式详解
JSON有两种结构 1. “名称/值”对的集合(A collection of name/value pairs). 不同的语言中,它被理解为对象(object),记录(record),结构(s ...
- 解决kafka集群由于默认的__consumer_offsets这个topic的默认的副本数为1而存在的单点故障问题
抛出问题: __consumer_offsets这个topic是由kafka自动创建的,默认50个,但是都存在一台kafka服务器上,这是不是就存在很明显的单点故障?经测试,如果将存储consumer ...
- docker 错误:Error response from daemon: cannot stop container: connect: connection refused": unknown
docker 错误:Error response from daemon: cannot stop container: 795e4102b2de: Cannot kill container 795 ...
- 【Python】微博自动抢红包
# -*- coding: utf-8 -*- import requests import js2xml from lxml import etree headers = { # 这边cookie替 ...