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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T13:39:58+00:00 2026-05-11T13:39:58+00:00

I have a very simple Country entity which I want to cache. This works

  • 0

I have a very simple Country entity which I want to cache. This works perfectly, but I want a clone version of the cached instance to be returned or be made read-only to prevent developers from changing the state of it.

How would I achieve this? I tought that the Fluent Readonly() method would enforce this, but it’s not the case.

Sample Fluent Mapping:

        Id(x => x.Id);         Map(x => x.Name).WithLengthOf(50).Not.Nullable().Unique();         Map(x => x.IsoCode).WithLengthOf(10).Not.Nullable().Unique();         HasMany(x => x.States).Cascade.None().LazyLoad();                   Cache.AsReadOnly(); 

My unit tests clearly indicates that the entities are cached and that the same entity is returned on subsequent gets, but I want the object to be immutable once it’s loaded from the persistent store.

Thanks!

  • 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. 2026-05-11T13:39:59+00:00Added an answer on May 11, 2026 at 1:39 pm

    If you want instances of your class to be immutable (in the sense that it’s impossible to modify object instances), then you’ll need to write your class according – it’s nothing to do with NHib or Fluent NHib. As an example, map NHib onto private fields or private property setters and only expose property getters publicly.

    With NHib it is possible to specify ‘mutable=false’ on your class mapping (not sure how to do this with FNH, sorry). This doesn’t make the object immutable at runtime, but it does inform NHib not to check for inserts, updates and deletes against these entities.

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

Sidebar

Related Questions

I have a very simple table called Member , which consists of the following:
I have this very simple jQuery function: $(.milestone-in-tree).live({ mouseenter: function() { setTimeout( $.ajax({ type:
I have a very simple highcharts js chart, which has dates on x-axis and
I have written very very simple console application which supports some command line options.
I'm sure this is very simple.We have an ajax call to a controller. The
I have very simple persistance.xml file: <?xml version=1.0 encoding=UTF-8?> <persistence version=1.0 xmlns=http://java.sun.com/xml/ns/persistence xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance xsi:schemaLocation=http://java.sun.com/xml/ns/persistence
I have very simple form, with input like this: <input id=my_id multiple=true type=file name=image_name[]
I have a very simple viewmodel class, and a strongly typed view (which uses
I am new to rails and have a very simple question but couldnt find
I have very simple question. I am not using it but I have curiosity

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.