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 6848789
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:54:43+00:00 2026-05-27T00:54:43+00:00

Using MongoDB I want to keep my model as clean as possible so I

  • 0

Using MongoDB I want to keep my model as clean as possible so I decided to follow this approach: http://www.mongodb.org/display/DOCS/CSharp+Driver+Serialization+Tutorial#CSharpDriverSerializationTutorial-RepresentationSerializationOptions

I have a class like:

public class Person
{        
    public string Name { get; set; }        
    public string Id { get; set; }

    public Person()
    {

    }
    public Person(string name)
    {            
        this.Name = name;            
    }
}

And inside application_start I have

BsonClassMap.RegisterClassMap<Person>(x =>
{
   x.AutoMap();
   x.IdMemberMap.SetRepresentation(BsonType.ObjectId);
});

But when it run I get a null reference exception on the IdMemberMap. Can someone please tell me if something is wrong?

  • 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-05-27T00:54:43+00:00Added an answer on May 27, 2026 at 12:54 am

    This is borderline to being a bug in the C# driver. Turns out IdMemberMap is not defined until the class map is “frozen”, for reasons having to do with class hierarchies in which the Id might actually be defined in a base class. One way to work around this is:

    BsonClassMap.RegisterClassMap<Person>(cm => {
        cm.AutoMap();
        cm.Freeze();
        cm.IdMemberMap.SetRepresentation(BsonType.ObjectId);
    });
    

    Another way to work around is to use GetMemberMap instead of IdMemberMap:

    BsonClassMap.RegisterClassMap<Person>(cm => {
        cm.AutoMap();
        cm.GetMemberMap(c => c.Id).SetRepresentation(BsonType.ObjectId);
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using MongoDB C# driver ( http://github.com/samus/mongodb-csharp ), seems that I'm unable to get the
I'm using MongoDB to store user profiles, and now I want to use GridFS
I want to store some genomic positions (chromosome,position) using MongoDB. something like: { chrom:chr2,
i am new to mongoDB. I am using mongoDB in web app. I want
I want to retrieve the last inserted _id , using mongoose as MongoDB wrapper
I want to build a webservice using mongodb and lithium. What is better: Store
I want to get visualized statistics from my data in mongodb using matplotlib, but
related to MongoDB Group using Ruby driver if I want to do something like
I'm currently using MongoDB to record application logs, and while I'm quite happy with
I am using MongoDB v1.4 and the mongodb-csharp driver and I try to group

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.