Primary key and MongoDB.Bson.ObjectId

In this topic:

There is following note:

Primary keys can be of type char, short, int, long, string, or MongoDB.Bson.ObjectId. Once you assign a property as a primary key, you cannot change it after an object of that type is added to a realm.

But, I get the following when I set my primary ket to a MongoDB.Bson.ObjectId:

Severity Code Description Project File Line Suppression State
Error Fody/Realm: Item.ID is marked as [PrimaryKey] which is only allowed on integral and string types, not on MongoDB.Bson.ObjectId. StretchedPenny D:\projects\MongoDBSP\StretchedPenny\StretchedPenny\StretchedPenny\Models\Items.cs 9

In Realm, what is the recommended way to create a unique key?

Are you using version 10.0.0-beta.2 of the SDK?

No, I was using 5.1.2 latest from NuGet. I have installed 10.0.0-beta-2 and that does indeed resolve the issue.

Might I suggest at minimum you add a header to the page that says:

Some features described in this topic require installation of a beta version of the SDK.

It would be a better user experience, but harder to maintain, to call out specific locations in the document where this is true.

You would also want to update any other pages where this could be an issue.

Thanks for your help.

This is briefly covered under the Install Realm section, but I’ll pass the feedback to the docs team.

Ahhh… yes. I see now. It really needs to be more explicit. I did not take away from that I needed to install the beta package. I suggest:

Add the Realm Beta Package

In the search bar, search for Realm . Check the “Show pre-release packages” checkbox and choose the latest beta release .Select the result and click Add Package. When prompted, select all projects and click Ok.

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.