Reputation: 60674
I'm experiencing an odd problem with FluentNHibernate: when I save my entity, one of the (reference) properties is not updated. Other properties, both fields and references, are updated, and the failing property is correctly mapped (retrieving entities works like a charm).
A (slightly simplified) description of what I'm doing:
InputModel
is bound and set. It has a property for the TypeID
, where I wish to set the Type
of my entity (let's call the entity type Thing
).Thing
object is created, and the simple properties of the InputModel
is copied over. For a couple of complex properties, among them the Type
property which isn't working and another property which is, the following is done:ThingType
is fetched from the repository, based on the provided type id.thing.Type = theType
) on the new Thing
object.Thing
that I want to update is fetched from the repository, based on the id on the input model (not the same id as the TypeID
).Thing
is saved, using session.Save();
. As stated above, it's only one property that isn't working - other properties, following (as far as I can tell) the exact same pattern, work. I've also debugged and verified that the original Thing
has the correct, updated Type
when it is passed to session.Save()
.
I have no idea where to start troubleshooting this...
Update: The classes are plain POCOs:
public class Thing
{
public int ID { get; set; }
public string SomeSimpleProp { get; set; }
public ThingType Type { get; set; }
public OtherEntity OtherReference { get; set; }
}
public class ThingType
{
public int ID { get; set; }
public string Name { get; set; }
}
My exact mappings (except for the names of types and properties) are these:
// In ThingMap : ClassMap<Thing> constructor:
Id(t => t.ID).Column("ThingID");
Map(t => t.SomeSimpleProp);
References(t => t.Type).Column("ThingTypeID");
References(t => t.OtherReference).Column("OtherReferenceID");
// In ThingTypeMap : ClassMap<ThingType> constructor:
Id(t => t.ID).Column("ThingTypeID");
Map(t => t.Name);
As I said, OtherReference
is updated correctly while Type
is not. They are mapped identically, so I don't see how this could be a mapping error.
Upvotes: 1
Views: 974
Reputation: 33272
You should specify <many-to-one .... cascade="save-update"/>
in order to update references.
Upvotes: 1