How to check if table (entity) exists in RavenDB
Asked Answered
P

1

6

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())
{

}
Peking answered 13/5, 2016 at 6:6 Comment(4)
I'm not sure that I follow. NotSupportedException will only be thrown if we can't actually process the query. Are you interested in a specified document, or in whatever anything exists there?Ranunculus
I am interested whether TimeoutData entity (table) exists in RavenDB at all. NotSupportedException is also thrown when TimeoutData does not exist, but I would like to implement more solid solution.Peking
if (!_session.Query<TimeoutData>().Any()) This should give you that informtionRanunculus
Turns out that I had to turn off pluralization of entity names and after that _session.Query<TimeoutData>().Any() started to work. This post helped me: #3636454. And also TimeoutData is NServiceBus entity for storing deferred messages.Peking
P
4

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.

Peking answered 18/5, 2016 at 19:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.