Will Dean
Will Dean

Reputation: 39500

Why can't I set ReadOnly on a Fluent NHibernate References() mapping?

In Fluent NHibernate, References() returns an object which doesn't support the 'ReadOnly()' method.

I'm trying to create this sort of mapping (i.e. one where an update is not propagated to the referred item):

<many-to-one update="false" insert="false" 
name="DestinationSheet" column="DestinationSheetNumber" />

On normal (map()) mappings, those two attributes can be set with ReadOnly().

I'd like to be doing something like this:

References(x => x.DestinationSheet).
       ColumnName("DestinationSheetNumber").ReadOnly();

I can manually add the update and insert attributes using SetAttributes(), and that works fine, but I am concerned that the fact that ReadOnly() is not present on References() is a clue that I shouldn't be trying to do this.

Does anyone know why ReadOnly() is not available in this context?

Upvotes: 4

Views: 3044

Answers (3)

Jon Masters
Jon Masters

Reputation: 513

Implementation of the answer provided by James Gregory is

References(x => x.Store).TheColumnNameIs("StoreId").SetAttribute("update","false");

Upvotes: 0

James Gregory
James Gregory

Reputation: 14223

It's simply not implemented yet. Over time we will come to support all the features of NHibernate, but until then the SetAttribute method is there to allow you to continue.

As an aside, we accept patches!

Upvotes: 5

Jamie Ide
Jamie Ide

Reputation: 49261

References creates a many-to-one mapping and according to the documentation, read only is not supported on this mapping. Your approach of setting update and insert to false sounds right to me. AFAIK, the Fluent NHibernate project plans to support all the mapping features of NHibernate, but until then you will have to use SetAttributes.

Upvotes: 0

Related Questions