Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if table (entity) exists in RavenDB

I am querying built-in TimeoutData entity in RavenDB using Raven.Client.Lightweight 2.5 library to get specific timeout document. It is possible that TimeoutData does not exist in the database because no document is stored there yet. In that case NotSupportedException is thrown when you try to query it.

Currently I have created workaround for this situation:

try
{
    timeoutData = _session.Query<TimeoutData>().FirstOrDefault(t => t.Headers.ContainsValue(someValue));
}
catch (NotSupportedException)
{
    return null;
}

Is it possible to verify if TimeoutData exist without using try-catch? I have also tried the following code but it returns false when documents exist in TimeoutData entity:

if (!_session.Query<TimeoutData>().Any())
{

}
like image 370
Viktors Telle Avatar asked May 13 '16 06:05

Viktors Telle


1 Answers

Turns out that I had to turn off pluralization of entity names and after that _session.Query<TimeoutData>().Any() started to work. Before doing that query tried to find entity named TimeoutDatas.

This post helped me: RavenDB changes metadata "Raven-Entity-Name".

And also I forgot to mention that TimeoutData is NServiceBus entity for storing deferred messages.

like image 52
Viktors Telle Avatar answered Nov 03 '22 09:11

Viktors Telle