Hi,
I found this gist and and copying the CreateDocumentsByEntityNameIndex method fixed my Index problem.
However, I can’t get the update working properly.
I want to rename an entity in the database and that’s how the implementation looks like:
_documentStore.DatabaseCommands.UpdateByIndex(
"Raven/DocumentsByEntityName",
new IndexQuery {
Query = "Tag:Groups"
},
new[]
{
new PatchRequest
{
Type = PatchCommandType.Modify,
Name = "@metadata",
Nested = new[]
{
new PatchRequest
{
Type = PatchCommandType.Set,
Name = "Raven-Entity-Name",
Value = new RavenJValue("Categories")
}
,
new PatchRequest
{
Type = PatchCommandType.Set,
Name = "Raven-Clr-Type",
Value = new RavenJValue("Foo.Entities.Category, Foo")
}
}
}
});
Again: what am I doing wrong?
Alex
From: rav...@googlegroups.com
[mailto:rav...@googlegroups.com] On Behalf Of Alexander Zeitler
Sent: Donnerstag, 9. August 2012 23:50
To: rav...@googlegroups.com
Subject: [RavenDB] Index Raven/DocumentsByEntityName existing in EmbeddableDocumentStore?
Hi,
I’m trying to write a test for data migrations using the EmbeddableDocumentStore in the test.
When executing this line:
_documentStore.DatabaseCommands.UpdateByIndex("Raven/DocumentsByEntityName",…)
I get the following Exception:
Raven.Database.Exceptions.IndexDoesNotExistsException
There is no index named: Raven/DocumentsByEntityName
Am I doing something wrong or does the referenced Index not exist by default when using EmbeddableDocumentStore?
Alex
Now I ran the patch code from below an existing database and noticed, that the patch is execute but the Id’s of the documents still contain the old entity name like “Groups/5” instead of “Categories/5”
How can I update the Id?
Do you mean DatabaseCommands or Session Commands? Can you give an example please?
Thanks
Alex
That doesn’t work as I’m using Guids and Load<Category>(id) because of the wrong id.
Instead I tried:
using (var session = _documentStore.OpenSession()) {
var categoryDefinitions = session.Query<CategoryDefinition>().ToList();
foreach (var category in categoryDefinitions) {
var id = category.Id;
session.Delete(category);
session.SaveChanges();
session.Store(category, Guid.NewGuid());
session.SaveChanges();
session.Delete(category);
session.SaveChanges();
session.Store(category, id);
session.SaveChanges();
}
}
This works but it feels pretty awkward… (and it only works when CategoryDefinitions collection has been empty).
Another approach has been this:
var groups = _session.Query<Group>();
foreach (var category in groups.Select(group => new Category () {
Id = group.Id,
// copy all properties
})) {
_session.Store(category);
}
}
But that requires to have both, Group and Category class, in the solution instead of just renaming Group to Category.
Will try your approach tomorrow with string id’s.