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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T13:29:12+00:00 2026-06-06T13:29:12+00:00

I’ve got the following model: public class Competitor { public virtual int CompetitorId {

  • 0

I’ve got the following model:

public class Competitor
{
    public virtual int CompetitorId { get; set; }
    public virtual string TeamName { get; set; }
    public virtual string FirstName { get; set; }
    public virtual string LastName { get; set; }
    public virtual DateTime BirthDate { get; set; }

    public virtual IEnumerable<CompetitorBest> CompetitorBests { get; set; }
}


public class CompetitorBest
{
    public virtual int ResultId { get; set; }
    public virtual string BestTypeName { get; set; }
    public virtual string IndoorOutdoor { get; set; }
    public virtual int Season { get; set; }
    public virtual string DisciplineName { get; set; }
    public virtual string ResultValue { get; set; }
}

When trying to save it to my MongoDB instance, I get the following error:

Maximum serialization depth exceeded (does the object being serialized have a circular reference?).

I’m using automapping (ie- not set any class mapping)

I can’t see what could be wrong?
There’s no circular reference?

  • 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-06T13:29:13+00:00Added an answer on June 6, 2026 at 1:29 pm

    Ok,
    I’m submitting this as an answer, mainly because it works – ie, allows me to save the document as required.

    As @chebum correctly pointed out, the problem is actually with the fact I’m pulling the entities using that model using nHibernate first.
    This means that my IEnumerable< CompetitorBest > on my Competitor object, is actually of type NHibernate.Collection.Generic.PersistentGenericBag

    As correctly pointed out by @chebum in the comments, this will have a reference to the original object, therefore creating a circular reference.

    Rather than create a mongodb class map (which is what I should probably do.. feel free to answer) this is what I did to get things working for now.

    Changed my Competitor class to this:

    public class Competitor
    {
        private IList<CompetitorBest> _competitorBests;
    
        //other properties
    
        public virtual IEnumerable<CompetitorBest> CompetitorBests
        {
            get { return _competitorBests.ToArray(); }
            set { }
        }
    }
    

    Then in my nHibernate Class Map:

    HasMany(x => x.CompetitorBests)
        .Not.LazyLoad()
        .Access.CamelCaseField(Prefix.Underscore)
        .Inverse()
        .AsBag()
        .KeyColumn("competitorId");
    

    Again, I’m sure there’s a better way of doing it (perhaps with a mongodb class mapping??)
    But i’ve added this as it works for me… for now.

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

Sidebar

Related Questions

I've got a string that has curly quotes in it. I'd like to replace
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
public static bool CheckLogin(string Username, string Password, bool AutoLogin) { bool LoginSuccessful; // Trim
i got an object with contents of html markup in it, for example: string
I want to count how many characters a certain string has in PHP, but
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
Specifically, suppose I start with the string string =hello \'i am \' me And
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

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.