【问题标题】:Marten OpenSession() vs LightweightSession()Marten OpenSession() 与 LightweightSession()
【发布时间】:2021-07-25 14:58:22
【问题描述】:

我是marten的新手。
IDocumentStore.OpenSession()IDocumentStore.LightweightSession() 有什么区别?

【问题讨论】:

    标签: c# postgresql nosql marten


    【解决方案1】:

    基于 xml doc 这只是一种方便的方法:

    在没有 IdentityMap 或自动脏检查的情况下创建新的“轻量级”IDocumentSession 的便捷方法

    在当前实现中,它只是将calls OpenSessionDocumentTracking 设置为DocumentTracking.None

    同样来自troubleshooting docs

    来自

    IDocumentStore.OpenSession

    特点

    默认为通过对象的身份跟踪对象的会话,DocumentTracking.IdentityOnly,隔离级别为 Read Committed

    使用: 读取和写入数据。会话中的对象按其身份进行缓存。通过会话操作(IDocumentSession.UpdateIDocumentSession.Store)显式控制对对象的更新。使用默认值,产生的开销低于DirtyTrackedSession

    来自

    IDocumentStore.LightweightSession

    特点

    没有更改跟踪,DocumentTracking.None,默认隔离级别为 Read Committed

    使用: 读取和写入数据。在会话中不缓存对象,例如使用相同的文档身份重复加载会产生单独的对象,每个对象都从数据库中提取。在对此类对象进行更新的情况下,要存储的最后一个对象将覆盖来自先前存储的具有相同身份的对象的任何未决更改。可以产生比跟踪会话更低的开销。

    【讨论】:

      猜你喜欢
      • 2011-12-24
      • 2015-11-12
      • 2014-06-21
      • 2013-11-10
      • 2014-03-10
      • 2016-04-20
      • 2016-12-21
      • 2012-12-10
      • 2012-07-06
      相关资源
      最近更新 更多