Domanda

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.

È stato utile?

Soluzione

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top