views:

875

answers:

3

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?

A: 

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.

Jamie Ide
Thanks for this - on the objects where Fluent Nh does already implement ReadOnly (e.g Map()), it does so merely by setting the insert and delete attributes - which are on the doc you quoted. I'm starting to think this is just an omission from Fluent.
Will Dean
And just realised that my mapping XML didn't make it into the original post, which made it rather difficult to follow, sorry.
Will Dean
+4  A: 

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!

James Gregory
There is already an open issue for this as well: http://code.google.com/p/fluent-nhibernate/issues/detail?id=203
Stuart Childs
Thanks - I was going to write a patch, but I see I've been beaten to it...
Will Dean
For people who don't know how to apply the patch, how do you apply the patch?
Jon Masters
Fluent NHibernate 1.0 has been released. Update to that, it should have the methods you need.
James Gregory
A: 

Implementation of the answer provided by James Gregory is

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