5

I'm just getting up to speed with NHibernate 3.2 and its "mapping by code" feature, and migrating our Fluent mapping over to it. Is there an equivalent of the fluent "ReadOnly();" function, to make the entire mapping read only? Thanks in advance.

Andrew Stephens
  • 9,413
  • 6
  • 76
  • 152

3 Answers3

7

Use Mutable(false) in the mapping.

Read this post for corresponding hbm file mapping from where I could infer this.

http://davybrion.com/blog/2007/08/read-only-data-in-nhibernate/

dreamerkumar
  • 1,540
  • 1
  • 18
  • 28
6

Use PropertyMapper action to define access style:

public class EntityMapping : ClassMapping<Entity>
{
     public EntityMapping()
     {
         Id(m => m.Id, map => map.Generator(Generators.HighLow));
         Property(m => m.Name, map => map.Access(Accessor.ReadOnly));
     }
}
cylon-v
  • 101
  • 1
  • 3
3

For those looking for this in fluent you are looking for ReadOnly() as below:

public class FooMap : ClassMap<Foo> {

    public FooMap() {
        Schema("bar");
        Table("foo");
        LazyLoad();

        ReadOnly();

        CompositeId()
            .KeyProperty(x => x.ID, "ID")
            .KeyProperty(x => x.Year, "Year");
        Map(x => x.FirstField).Column("FirstField").Length(1);
    }
}
mcfea
  • 1,129
  • 15
  • 22