OrientDB-NET.binary
OrientDB-NET.binary copied to clipboard
Creating uniq ID fields with sequence.next()
I encountered a problem when export-import DB the RIDs changes on the records. So after some googling I found that RID may be recycled after removing the record. And really after the import of the DB RIDs can change.
There are some ways to create really uniq id. One of the ways is to create sequence. And I think because of all records are V type there should be only one sequence for all nodes. So, it would be cool to create vertices with sequence.next() like in java api example.
OSequence seq = graph.getRawGraph().getMetadata().getSequenceLibrary().getSequence("idseq");
graph.addVertex("class:Account", "id", seq.next());
@aligin What's your goal, I'm not really sure what you are trying to solve here in your own code.
I must have a unique Id of my record, that I can refer in the other services. I thought that RID is that unique immutable identifier, but it's not. When you export DB (backup) and then reimport the RIDS of your records can change. So I've created the field Id. I've created the sequence. But to properly add new record I must do
var id = database.Query<Sequence>("select sequence('idseq').next()").FirstOrDefault();
var vertex = database
.Create.Vertex(obj)
.Set("Id", id.sequence)
.Run<T>();
There are I guess two database calls although you can make one.