How to use C# 9.0's record feature in RavenDB?

127 views
Skip to first unread message

Arash Sabet

unread,
Jan 17, 2021, 7:10:49 AM1/17/21
to RavenDB - 2nd generation document database
I have a C# 9.0 record and when trying to save it, I get the following exception from RavenDB's client:

Raven.Server.Rachis.RachisApplyException: In ClusterTransactionDataCommand document id cannot be null, empty or white spaces as part of cluster transaction. Type:(PUT), Index:(0)
   at Raven.Server.ServerWide.Commands.ClusterTransactionCommand.ClusterCommandValidation(ClusterTransactionDataCommand command, Char identityPartsSeparator)
   at Raven.Server.ServerWide.Commands.ClusterTransactionCommand..ctor(String databaseName, Char identityPartsSeparator, String recordId, ArraySegment`1 commandParsedCommands, ClusterTransactionOptions options, String uniqueRequestId)
   at Raven.Server.Documents.Handlers.BatchHandler.HandleClusterTransaction(DocumentsOperationContext context, MergedBatchCommand command, ClusterTransactionOptions options)
   at Raven.Server.Documents.Handlers.BatchHandler.BulkDocs()
   at Raven.Server.Routing.RequestRouter.HandlePath(RequestHandlerContext reqCtx)
   at Raven.Server.RavenServerStartup.RequestHandler(HttpContext context). Response: {"Url":"/databases/InPremDev/bulk_docs?raft-request-id=007ae1cf-c947-4ef9-ad4b-c022087a1460","Type":"Raven.Server.Rachis.RachisApplyException","Message":"In ClusterTransactionDataCommand document id cannot be null, empty or white spaces as part of cluster transaction. Type:(PUT), Index:(0)","Error":"Raven.Server.Rachis.RachisApplyException: In ClusterTransactionDataCommand document id cannot be null, empty or white spaces as part of cluster transaction. Type:(PUT), Index:(0)\r\n   at Raven.Server.ServerWide.Commands.ClusterTransactionCommand.ClusterCommandValidation(ClusterTransactionDataCommand command, Char identityPartsSeparator)\r\n   at Raven.Server.ServerWide.Commands.ClusterTransactionCommand..ctor(String databaseName, Char identityPartsSeparator, String recordId, ArraySegment`1 commandParsedCommands, ClusterTransactionOptions options, String uniqueRequestId)\r\n   at Raven.Server.Documents.Handlers.BatchHandler.HandleClusterTransaction(DocumentsOperationContext context, MergedBatchCommand command, ClusterTransactionOptions options)\r\n   at Raven.Server.Documents.Handlers.BatchHandler.BulkDocs()\r\n   at Raven.Server.Routing.RequestRouter.HandlePath(RequestHandlerContext reqCtx)\r\n   at Raven.Server.RavenServerStartup.RequestHandler(HttpContext context)"}

The record looks like the following code snippet. Is this because a record instance is an immutable entity?

public record Model(string Id);

public record User
(
int UserId,
string Id,
string Login
) : Model(Id);

What is the solution for this problem?

Grisha Kotler

unread,
Jan 17, 2021, 10:46:06 AM1/17/21
to rav...@googlegroups.com
Hi,

It looks like it's part of a cluster transaction.
You must set the id of the entity before saving.

Grisha Kotler
Team Leader   /   Hibernating Rhinos LTD
Skype:  grisha.kotler
Support:  sup...@ravendb.net
  


--
You received this message because you are subscribed to the Google Groups "RavenDB - 2nd generation document database" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ravendb/78de70b0-91fb-4fe1-8e65-6af5b6c9084fo%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages