、事务支持
别的关系型数据库和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学习(八)高级特性上半部分的更多相关文章

  1. php面向对象编程学习之高级特性

    前几天写了一篇关于php面向对象基础知识的博客,这两天看了php面向对象的高级特性,写出来记录一下吧,方便以后拿出来复习. 面向对象除了最基本的定义类之外,最主要就是因为面向的一些高级特性,运用这些高 ...

  2. Python学习札记(十八) 高级特性4 生成器

    参考:生成器 Note 1.通过列表生成式,我们可以直接创建一个列表.但是,受到内存限制,列表容量肯定是有限的,且容易造成空间浪费.所以,如果列表元素可以按照某种算法推算出来,那我们可以在循环的过程中 ...

  3. nginx 学习八 高级数据结构之基数树ngx_radix_tree_t

    1 nginx的基数树简单介绍 基数树是一种二叉查找树,它具备二叉查找树的全部长处:检索.插入.删除节点速度快,支持范围查找.支持遍历等. 在nginx中仅geo模块使用了基数树. nginx的基数树 ...

  4. Python学习之高级特性

    切片 在Python基础篇里,我们知道Python的可序列对象可以通过索引号(下标)来引用对象元素,索引号可以由0开始从左向右依次获取,可以从-1开始由右向左获取.这种方法可以帮助我们依次获取我们想要 ...

  5. python学习之高级特性:

    切片:对列表.元组.字符串.字典取中间的一部分,在C中一般是通过for循环拷贝/memcpy/strcat等操作.而python提供了更方便的切片操作符[m:n]:前闭后开,如果从0取m可以省略:如果 ...

  6. python切片、迭代、生成器、列表生成式等高级特性学习

    python高级特性 1行代码能实现的功能,决不写5行代码.请始终牢记,代码越少,开发效率越高. 切片 当我们要取一个list中的前n各元素时,如果前n个少的话,我们还可以一个一个的取,但是若前n个元 ...

  7. 消息中间件——RabbitMQ(八)高级特性全在这里!(下)

    前言 上一篇消息中间件--RabbitMQ(七)高级特性全在这里!(上)中我们介绍了消息如何保障100%的投递成功?,幂等性概念详解,在海量订单产生的业务高峰期,如何避免消息的重复消费的问题?,Con ...

  8. Python3学习(二)-递归函数、高级特性、切片

    ##import sys ##sys.setrecursionlimit(1000) ###关键字参数(**关键字参数名) ###与可变参数不同的是,关键字参数可以在调用函数时,传入带有参数名的参数, ...

  9. Spring框架学习[IoC容器高级特性]

    1.通过前面4篇文章对Spring IoC容器的源码分析,我们已经基本上了解了Spring IoC容器对Bean定义资源的定位.读入和解析过程,同时也清楚了当用户通过getBean方法向IoC容器获取 ...

随机推荐

  1. C#基础第八天-作业-设计类-面向对象方式实现两个帐户之间转账

    要求1:完成以下两种账户类型的编码.银行的客户分为两大类:储蓄账户(SavingAccount)和信用账户(CreditAccount),两种的账户类型的区别在于:储蓄账户不允许透支,而信用账户可以透 ...

  2. MySQL Metadata Lock详解

    Metadata Lock 的作用: 要直接说出Metadata Lock 的作用.以我目前的文字功底是不行的.好在我可以通过一个例子来说明. 假设session 1 在正在执行如下的SQL语句 se ...

  3. js页面加载完后执行(document.onreadystatechange 和 document.readyState)

    js页面加载完后执行javascript(document.onreadystatechange 和 document.readyState) document.onreadystatechange ...

  4. jQuery添加/改变/移除CSS类

    转自:http://www.jbxue.com/article/24589.html 在jquery中用到removeClass移除CSS类.addClass添加CSS类.toggleClass添加或 ...

  5. c#中lock的使用(用于预约超出限额的流程)

    一个项目,预约系统,核心二张表:预约表,预约限额表 用户点击预约按钮后, 1. 先select 预约限额表把该预约时间段的限额取出来, 2. 再select 预约表把该预约时间已经预约上的次数算出来 ...

  6. Atitit jquery  1.4--v1.11  v1.12  v2.0  3.0 的新特性

    Atitit jquery  1.4--v1.11  v1.12  v2.0  3.0 的新特性 1.1. Jquery1.12  jQuery 2.2 和 1.12 新版本发布 - OPEN资讯.h ...

  7. AWS产品目录

    计算 Amazon EC2:弹性虚拟机 AWS Batch:批处理计算 Amazon ECR:Docker容器管理 Amazon ECS:高度可扩展的快速容器管理服务 Amazon EKS:在AWS上 ...

  8. u3d中的坐标系

    任何子级游戏对象 (Child GameObject) 的检视器 (Inspector) 中的变换 (Transform) 值都会相对于父级 (Parent) 的变换 (Transform) 值而显示 ...

  9. 20、uwp打包失败(All app package manifests in a bundle must declare the same values under the XPath *[local-name()='Package']/*[local-name()='Dependencies'])

    在给 uwp工程打商店包的时候,遇到了一个异常: Error info: error 80080204: All app package manifests in a bundle must decl ...

  10. 【Android】ADB常用指令与logcat日志

    ADB命令简介 ADB是一个功能强大的命令行工具.通过它可以直接和模拟器或真机进行交互.它是一个具有客户端和服务器端的程序. 它主要由三个部分组成: 客户端,它运行在你的开发机上,你可以通过执行adb ...