Raven DB - auto generate your own key

I current has an object that has the public property Id. When I store an object, I would like the Id to be part of the data and not become the Id document as it currently works. When creating a document repository, I install only the connection string.

using (var session = documentStore.OpenSession())
{
    session.Store(a);
    session.SaveChanges();
}


a can be thought of an object as:
public class A
{
    public Guid Id { get; set; }
    //other properties
}

So either I want it to generate a random identifier, or have both data and documentId, which are a property of Id of class A.

EDIT:

So, two possibilities: 1. Document Id = Id and

Data Section contains:
{
    data //sorry if the notation is not correct, doing it off of memory
    {
        Id: [my guid] 
        //other properities
    }
}

Or data containing id and document id = randomly generated raven

+5
source share
1 answer

, , Id , , , raven, :

public class User
{
    public string DocumentId { get; set; }
    public Guid Id { get; set; }
    public string Name { get; set; }

    public User()
    {
        Id = Guid.NewGuid();
    }
}

documentStore.Conventions.FindIdentityProperty = prop =>
{
    if (prop.DeclaringType == typeof(User))
        return prop.Name == "DocumentId";

    return prop.Name == "Id";
};
+8

All Articles