开发者

Put transient entity in cache without persisting it

I have a method that is responsible for loading entities sort of like a DAO. If the entity is not found, the method is supposed to create a new entity and return that instead. However, the new entity should not be persisted just yet.

The problem is that the method may be called again to fetch the same entity within the same session scope, and then it's supposed to return the previously created (but not persisted) entity. Is it possible to put the entity in NHibernate's cache so it can find it (without persisting it开发者_StackOverflow), or do I need to implement my own cache mechanism to handle new entities?


While it may be possible to add an entity to the PersistenceContext with a Status of Gone. Whether or not that would even accomplish what you might want is dubious, not to mention the fact that rolling your own temp object cache would be a lot simpler than trying to call this API.

public EntityEntry AddEntry(object entity, Status status, object[] loadedState, 
                            object rowId, object id, object version, 
                            LockMode lockMode, bool existsInDatabase, 
                            IEntityPersister persister, 
                            bool disableVersionIncrement, 
                            bool lazyPropertiesAreUnfetched)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜