[英]How to get Raven DB index name from clr type
Is there a way I can get index name from corresponding class in c#? 有没有一种方法可以从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. 例如:我有一个名为
Users_ByEmail
类,并且我知道Raven为我创建了一个名为Users/ByEmail
索引,但是我想从Raven方法中获取它。
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? Raven客户端有任何公开的方法吗? This would be useful, because I don't want use strings when calling
UpdateByIndex
method from DataBaseCommands. 这将很有用,因为从DataBaseCommands调用
UpdateByIndex
方法时,我不想使用字符串。
You can get the name by creating an instance of the class and using the IndexName
property. 您可以通过创建类的实例并使用
IndexName
属性来获取名称。
string indexName = new Users_ByEmail().IndexName;
I agree it would be nice if the API had some overloads that didn't rely on string. 我同意,如果API有一些不依赖字符串的重载,那将是很好的。 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. 如果您的代码中有很多这样的调用,则可以考虑编写一个扩展方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.