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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T17:50:18+00:00 2026-05-19T17:50:18+00:00

I have a situation where say, a Notebook stores Pages . At first, I

  • 0

I have a situation where say, a Notebook stores Pages. At first, I had it structured like this.

class Notebook
{
 // ...
 public virtual IList<Page> Pages
 {
  get;
  set;
 }
}

class Page
{
 // ..
 public virtual int Number
 {
  get;
  set;
 }
}

That worked okay. Each page had a page number. I would have the ability to re-order pages in my UI, and update the number. No problem. Then I discovered I could use a Dictionary, and simplify it more…

class Notebook
{
 // ...
 public virtual IDictionary<int, Page> Pages
 {
  get;
  set;
 }
}

class Page
{
 // ..
}

And map it like so..

public class NotebookMap : ClassMap<Notebook>
{
    public NotebookMap()
    {
        // Specify the Entity Primary Key
        Id(x => x.Id);

        // one notebook will have a list of pages with page numbers
        HasMany<int, Page>(x => x.Pages)
            .DictionaryKey<int>("Number")
            .DictionaryValue<Page>("Page")
            .ForeignKey("Notebook")
            .Schema("Notebook").Table("Pages"); 

        Schema(Schemas.Collections ); Table("Notebooks");
    }
}

Huzzah, everything was right with the world. This works great. But I’m curious…

Is there any way to bind Number to something that will make sure to auto-increment per Notebook? Right now, I just handle this in my Service by using the Notebook.Pages.Count method when I add a new page. But fluent nHibernate seems pretty smart. Is there any way I can integrate it right into the mapping, so that anytime I add a new page, it just gets the count and makes sure the number is appropriate?

  • 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-19T17:50:19+00:00Added an answer on May 19, 2026 at 5:50 pm

    I think you really want to keep this out of the mapping. You’d be mixing the application logic (Where should the next page go) with the model (how am I storing the next page). Also if you make this column auto-increment you’d have to do it on a per table basis. Unless you are creating a new table for each book, you’d (AFAIK) only be able to have 1 consistently incrementing key (as the native generator which uses auto increment columns in NHibernate is done via the database).

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

Sidebar

Related Questions

Say I have some situation like this: class Vertex { public: Position position; Normal
I have a situation: Class B in it's own Bundle (say Bundle-B-1.0.0). Class A
A general architecture question in Sitecore 6... Let’s say we have a situation where
Hypothetical situation: let's say I have a 3rd party .net assembly being used in
I have the situation where i use GIS software which stores the information about
I have a situation say I have to print Notification viewed when local notification
The situation: Say I have an example controller called AccountController with some actions of
Let's say you have a situation where your Symfony application cannot get its database
I have this situation: <div A> <div B> <div C> Div A is a
I'm trying to determine what situations MySQL updates an index. Say I have the

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.