I'm really not clear on Fluent NHibernate mappings. I'm trying to do
something simple, and I'm not able to figure out how to do it.

My project has a User class and a UserProfile class. A User object
contains the basic frequently-used information about a user (username,
password, default profile picture path, etc.), and a UserProfile class
contains details that are used less often (address, phone number,
etc.). Every User will have exactly one unique UserProfile. The User
class contains a foreign key to the UserProfile class, but not the
other way 'round, because I'll never need to look up the user for a
given profile.

I want to set this up so that when I create a User, the User object
automatically creates its UserProfile object. My project calls:

User newUser = new User();
userRepository.SaveOrUpdate(newUser);

and my User class contains the property:

public virtual UserProfile userProfile { get; set; }

and in the constructor,

userProfile = new UserProfile();

When I run this code, I get an "object references an unsaved transient
instance - save the transient instance before flushing" error because
it's not saving the UserProfile object.

So in UserMappingOverride.cs, I set:

mapping.HasOne(x => x.UserProfile).Cascade.All();

Now I don't get an error, but the UserProfile object isn't saved to
the database, and newUser.userProfile is null.

How do I get this to work? And, what's the best concise reference for
achieving a better understanding of how mappings work? I've found a
lot of documentation, but it just hasn't clicked so far.

-- 
You received this message because you are subscribed to the Google Groups 
"Fluent NHibernate" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/fluent-nhibernate?hl=en.


Reply via email to