Question

Is there a way I can get index name from corresponding class in c#? For example: I have class named Users_ByEmail and I know that Raven created index named Users/ByEmail for me, but I want to get it from Raven methods.

I need something like this:

public class Users_ByEmail : AbstractIndexCreationTask<User>
....

string indexName = documentStore.GetIndexName(typeof(Users_ByEmail));

Is Raven client has any method doing that exposed? This would be useful, because I don't want use strings when calling UpdateByIndex method from DataBaseCommands.

Was it helpful?

Solution

You can get the name by creating an instance of the class and using the IndexName property.

string indexName = new Users_ByEmail().IndexName;

I agree it would be nice if the API had some overloads that didn't rely on string. Something like the following would be nice:

documentStore.DatabaasCommands.UpdateByIndex<Users_ByEmail>(...)

If you have a lot of these calls in your code, you could consider writing an extension method that would give you that.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top