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容器获取 ...
随机推荐
- 温故而知新 phpstudy 设置 nginx 代理
nginx.conif 找到 server 关键字配置 server { listen ; server_name localhost; #charset koi8-r; #access_log lo ...
- 纯干货,Spring-data-jpa详解(转)
本篇进行Spring-data-jpa的介绍,几乎涵盖该框架的所有方面,在日常的开发当中,基本上能满足所有需求.这里不讲解JPA和Spring-data-jpa单独使用,所有的内容都是在和Spring ...
- Android之四大组件、六大布局、五大存储 总结
Android之四大组件.六大布局.五大存储 一.四大组件:Android四大组件分别为activity.service.content provider.broadcast receiver. ...
- sublime unityshaderplugin
- 类里的通用成员函数应声明为static
类C的成员函数f,如果f的实现实现不依赖于C的任何成员变量,则f为通用函数. 对于通用函数f,可以将其从类C中分离出来做成一个全局函数,也可以仍然让它属于类C,但加上static. 两种处理方法实际都 ...
- CentOS中安装JAVA环境
好消息, 程序员专用早餐机.和掌柜说 ideaam,可以节省20元. 点击链接 或復·制这段描述¥k3MbbVKccMU¥后到淘♂寳♀ 一般情况下,我们都要将linux自带的OPENJDK卸载掉, ...
- centos 6.5 上安装使用upsource
这里应领导的要求,在服务器上装了upsource Upsource的安装和与JetBrains工具的集成 JetBrains的工具一直都是我开发和学习的好帮手,本人工作主要是iOS开发,使用的是App ...
- ssh转发
ssh有3种转发:本地转发,远程转发,动态转发. 1.本地转发:当client和ssh-client的方向一致的时候,就是本地转发. 限制:1)client直接访问server被防火墙阻挡.2)ssh ...
- 解决Unity协程无法同步返回的问题
Unity的协程是轻量的异步解决方案,但是每调用一次yield就必须等下一帧才能继续,这一点带来了很多约束. 比如如下代码: void OnEnable() { StartCoroutine(_Do( ...
- x86-64整数寄存器