Copying files
var photoId = db.Mapper.GetProperty<IVenue>(v => v.Photo).Id;
// one file, from one node's property to another's
FileValue? copy = await db.FileCopyAsync(original.Id, photoId, duplicate.Id, photoId);
// several, in one transaction
FileValue?[] copies = await db.FileCopyAsync(pairs.Select(p =>
(new PropertyPath(p.From, photoId), new PropertyPath(p.To, photoId))));A copy gets the source's file with its name and meta data. When the file store keeps one copy per
content (SameHashSameFile, §12.1), the two share the stored
file and no bytes move. The result lists the new values in order, with null where the source has no
file.
To write a copy together with other changes, such as the insert of its node, add it to a
TransactionData:
var duplicate = db.Create<IVenue>();
duplicate.Name = original.Name + " (copy)";
var td = new TransactionData();
td.InsertOrFail(db.Mapper.CreateNodeDataFromObject(duplicate, null, null), null, null);
var copy = td.CopyFile(new PropertyPath(original.Id, photoId), new PropertyPath(duplicate.Id, photoId));
db.Execute(td);
FileValue? photo = copy.Result; // set once the transaction has runThe source must be stored already; the target may be inserted earlier in the same transaction.