Looking further into this issue, we might have found a way to get this result using the IDocumentStoreListener and IDocumentConversionListener. Is there a reason why we would not use this approach?
public class TestObject
{
public string Id { get; set; }
public Guid? Etag { get; set; }
}
public class DocumentConversionListener : IDocumentConversionListener
{
public void DocumentToEntity(object entity, RavenJObject document, RavenJObject metadata)
{
var x = entity as TestObject;
if (x != null)
{
x.Etag = metadata.Value<Guid>("@etag");
}
}
public void EntityToDocument(object entity, RavenJObject document, RavenJObject metadata)
{
return;
}
}
public class DocumentStoreListener : IDocumentStoreListener
{
public void AfterStore(string key, object entityInstance, RavenJObject metadata)
{
var x = entityInstance as TestObject;
if (x != null)
{
x.Etag = metadata.Value<Guid>("@etag");
}
}
public bool BeforeStore(string key, object entityInstance, RavenJObject metadata)
{
return true;
}
}