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

  • Home
  • SEARCH
  • 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 6169435
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T22:51:30+00:00 2026-05-23T22:51:30+00:00

I’ve got the following classes: public class Client { public virtual Guid ClientID {

  • 0

I’ve got the following classes:

public class Client {
    public virtual Guid ClientID { get; set; }
    public virtual string ClientName { get; set; }
    public virtual IList<ClientMonthlyRevenue> Revenue { get; set; }

    ...
    public virtual void SetMonthlyRevenue(int year, int month, double revenue)
    {   
        // Make sure it's not null... this might happen depending on how the client is created    
        if (Revenue == null)
        Revenue = new List<ClientMonthlyRevenue>();

        // Check for existance - we don't want any duplicates        
        ClientMonthlyRevenue clientMonthlyRevenue = Revenue.Where(x => x.Year == year && x.Month == month).FirstOrDefault();        
        if (clientMonthlyRevenue == null)        
        {
            // If it doesn't exist, create a new one and add to the list
            clientMonthlyRevenue = new ClientMonthlyRevenue(this, year, month, revenue);
            this.Revenue.Add(clientMonthlyRevenue);   // This is the line throwing the error
        }
        else
        {
            // If it exists, just update it
            clientMonthlyRevenue.Revenue = revenue;
        }
    }
}

public class ClientMonthlyRevenue {
    public virtual Client ParentClient { get; set; }
    public virtual int Year { get; set; }
    public virtual int Month { get; set; }
    public virtual double Revenue { get; set; }

    ...
}

And these two mappings:

public class ClientMap : ClassMap<Client>
{
    Id(x => x.ClientID).GeneratedBy.Assigned();
    Map(x => x.ClientName);

    HasMany<ClientMonthlyRevenue>(x => x.Revenue)
        .Table("ClientMonthlyRevenue")
        .KeyColumn("ClientID")
        .Cascade.All()
        .Fetch.Join();
}

public class ClientMonthlyRevenueMap : ClassMap<ClientMonthlyRevenue>
{
    CompositeId()
        .KeyReference(x => x.Client, "ClientID")
        .KeyProperty(x => x.Year)
        .KeyProperty(x => x.Month);

    Map(x => x.Revenue);
}

When I get a Client from the database:

Client client = Session.Get<Client>(clientID);

all the data is there, which is great. But when I try to add a new ClientMonthlyRevenue child:

client.Revenue.Add(new ClientMonthlyRevenue(this.ClientID, year, month, revenue));

I get the error:

Collection was of a fixed size. 

Am I missing or misunderstanding something here? And what do I need to modify to be able to add items to this persisted list?

  • 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-23T22:51:31+00:00Added an answer on May 23, 2026 at 10:51 pm

    I would change the Client object to have the following:

    public class Client
    {
        public Client()
        {
            Revenue = new List<ClientMonthlyRevenue>();
        }
    
        public virtual Guid ClientID { get; set; }
        public virtual string ClientName { get; set; }
        public virtual IList<ClientMonthlyRevenue> Revenue { get; set; }
    
        public virtual void AddRevenue(ClientMonthlyRevenue revenue)
        {
            revenue.ParentClient = this;
            Revenue.Add(revenue);
        }
    }
    

    Then you can call like this:

    public void TestMapping()
    {
        session.BeginTransaction();
        var client = new Client{ClientID = Guid.NewGuid()};
        session.SaveOrUpdate(client);
    
        client = session.Get<Client>(client.ClientID);
        client.AddRevenue(new ClientMonthlyRevenue(2001,07,1200));
        session.Transaction.Commit();
    }
    

    The error you are receiving sounds like it could be created higher up in the stack. I was able to recreate your scenario. See full source: https://gist.github.com/1098337

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

Sidebar

Related Questions

i got an object with contents of html markup in it, for example: string
I've got a string that has curly quotes in it. I'd like to replace
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
Does anyone know how can I replace this 2 symbol below from the string
I have just tried to save a simple *.rtf file with some websites and
I have a JSP page retrieving data and when single or double quotes are
Seemingly simple, but I cannot find anything relevant on the web. What is the
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

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.