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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:14:54+00:00 2026-05-28T13:14:54+00:00

I am new to nhibernate and have been looking at repository patterns. The problem

  • 0

I am new to nhibernate and have been looking at repository patterns. The problem I am having is how should I deal with object relationships especially saving new sub objects with a generic-repository?

Am I right in thinking that the best solution is to create a new instance of a generic-repository of the type of the sub object and use that to save them? (pseudo code below)

GenericRepository<Product> genrep1 = new GenericRepository<Product>(session);
Product prod = genrep1.find(1);
Category cat = new Category();
GenericRepository<Category>() genrep2 = new GenericRepository<Category>(session)
genrep2..save(cat);
prod.category = cat;
genrep1.save(prod);

Or am I missing something?
Or perhaps there is a better way?

  • 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-28T13:14:54+00:00Added an answer on May 28, 2026 at 1:14 pm

    If you set the Product.category as cascade.SaveUpdate (or some other kind of cascade) in your mapping you only need to save the Product object and all child object will be saved (or update) automatically.

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

Sidebar

Related Questions

I'm new to NHibernate... I have been following this NHibernate Tutorial from Gabriel Schenker
I am new to NHibernate and have found it extremely interesting. I have been
I'm relatively new to NHibernate, but have been using it for the last few
I am new to NHibernate and have just started right now. I have very
I'm pretty new to NHibernate. I have working many to many mappings. they look
I'm new to NHibernate and Fluent NHibernate. Assuming I have a situation like the
I'm new to NHibernate and trying to create my first mapping. I have created
I'm quite new to hibernate and have stumbled on this problem, which I can't
I'm new to Hibernate and I'm struggling with problem: I have 3 tables and
I am looking to start work on a brand-new project, something I've been thinking

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.