Accessing a single RavenDB from different applications

安稳与你 提交于 2019-12-11 10:54:01

问题


I have a web project that stores objects in raven db. For simplicity the classes live in the web project.

I now have a batch job that is a separate application that will need to query the same database and extract information from it.

Is there a way I can tell raven to map the documents to the classes in the batch job project that have the same properties as those in the web project.

I could create a shared dll with just these classes in if that's needed. seems unnecessary hassle though


回答1:


As long as the structure of the classes you are deserializing into partially matches the structure of the data, it shouldn't make a difference.

The RavenDB server doesn't care at all what classes you use in the client. You certainly could share a dll, or even share a portable dll if you are targeting a different platform. But you are correct that it is not necessary.

However, you should be aware of the Raven-Clr-Type metadata value. The RavenDB client sets this when storing the original document. It is consumed back by the client to assist with deserialization, but it is not fully enforced. The logic basically is this:

is there ClrType metadata?
  if yes, do we have that type loaded in the current app domain?
    if yes, then deserialize into that type

if none of the above, then deserialize dynamically and cast into the type
requested (basically, duck-typing)

You can review this bit of the internals in the source code on github here.



来源:https://stackoverflow.com/questions/13270681/accessing-a-single-ravendb-from-different-applications

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!