The RavenDb documentation states:
Numeric or Guid Id properties are supported and will work seamlessly. In this case, RavenDB will automatically make the translation between the inner string ID to the numeric or Guid value shown in the entity and back.
I have stored the following objects:
class A
{
public Guid Id { get; set; }
public Guid BId { get; set; }
}
class B
{
public Guid Id { get; set; }
public string Name { get; set; }
}
I have then created the following projection:
class AB
{
public Guid Id { get; set; } // This should be the Id of A
public Guid BId { get; set; } // This should be the Id of B
public string BName { get; set; } // This should be the name of B
}
I have created the following index to create the projection:
class MyIndex : AbstractIndexCreationTask<AB>
{
public MyIndex()
{
Map = docs =>
from d in docs
select new
{
d.Id,
d.BId,
BName = string.Empty
};
TransformResults = (database, results) =>
from r in results
let b = database.Load<B>("bs/" + r.BId.ToString())
select new
{
r.Id,
r.BId,
BName = b.Name
};
}
}
When I use the following query:
session.Query<AB, MyIndex>().FirstOrDefault(t => t.Id == guid);
I get this exception:
Error converting value "bs/cc0a65ae-dd36-4437-8a57-fa20b91eeef7" to type 'System.Guid'. Path 'Id'.
Questions:
It is caused by the conversion in my projection since the
Idis a string there and not my Guid anymore. However, leaving it out will not return the Id. What must I do?I have to use the string building
"bs/" + r.BId.ToString()to load the related doc. Is there a way not having to do this? Is there some sort of function that would resolve the doc tag for me?Is there a generic way to strip out the document tag altogether?
My constraints.
I will generate the Guid and cannot let RavenDb generate it for me. I know that the Document ID in reality is string, but I really need to use a Guid that I create. I would prefer to own the Id property of my entities.
I'm using Raven.Client 1.0.972