Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9018387
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T04:30:53+00:00 2026-06-16T04:30:53+00:00

I have set the SetIdMember() for a class map to point to an element

  • 0

I have set the SetIdMember() for a class map to point to an element within the object:

BsonClassMap.RegisterClassMap<Person>(x =>
    {
        x.AutoMap();
        x.SetIdMember(x.GetMemberMap(p => p.PersistedId));
    });

Which works fine, however I was looking in the mongo data (via MongoVUE) and noticed that the PersistedId field is not stored anywhere in the database, I presume this is because it maps it to the _id field.

Now for 99% of scenarios im sure that is fine, however in this case I am using a non-strongly typed model, and pulling back a raw BsonDocument, then turning it to JSON for handing to a clientside script to then use further. However it is expecting to get a PersistedId field in the JSON but it doesn’t exist, it is just _id.

So is there a way for me to get it to do its whole unique _id field thing, but also get it to write out the PersistedId field to the database too? (I know its going to be duplicated data, but its not a major worry)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T04:30:54+00:00Added an answer on June 16, 2026 at 4:30 am

    You can add a readonly property and let the driver know to store it in the database as PersistedId.

    public class Entity
    {
        public ObjectId Id { get; set; }
    
        public ObjectId PersistedId 
        {
            get { return Id; }
        }
    }
    
    BsonClassMap.RegisterClassMap<Person>(x =>
    {
        x.AutoMap();
        x.MapMember(x => x.PersistedId);
    });
    

    However, I’m not sure this is the best idea. You likely shouldn’t be sharing your database models with your UI in a server environment like this. Rather, you should be mapping from your database models to UI models. This provides a large number of benefits, such as aggregating models, transforming models, etc… so that your UI isn’s so coupled to your UI. But, ultimately, it is your call.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have set a background on the data-role=page element like so <div data-role=page style=background:
I have set of data point (x_i,y_i) from a text file. How can I
I have set up my database so that the ID property of my class
I have set of markers on my map view. I want to get the
I have set my own OSM server for providing map tiles to use in
I have set a custom tint color for a UINavigationBar (within a UINavigationController )
I have set the Timeout property of SmtpClient class, but it doesn't seem to
I have set the eclipse java formatter to wrap lines that exceed 120 characters
I have set up Eclipse Indigo to do line debugging with CFEclipse over port
I have set up upload_max_filesize and post_max_size to 32Mb in php.ini. I am using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.