Andrew Stephens
Andrew Stephens

Reputation: 10193

How to set entire mapping to read only in NHibernate 3.2 mapping-by-code?

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.

Upvotes: 5

Views: 4057

Answers (3)

mcfea
mcfea

Reputation: 1139

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);
    }
}

Upvotes: 3

cylon-v
cylon-v

Reputation: 101

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));
     }
}

Upvotes: 6

dreamerkumar
dreamerkumar

Reputation: 1550

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/

Upvotes: 7

Related Questions