I cannot find an example on this. I’m trying to get a basic understanding of Fluent NHibernate but resources seem quite scarce in terms of proper tutorials.
I have a test class like this:
public class User
{
public virtual long ID { get; set; }
public virtual string Username { get; set; }
public virtual MoreDetails ExtendedDetails { get; set; }
}
With another class like this:
public class MoreDetails
{
public virtual long ID { get; set; }
public virtual string Firstname { get; set; }
public virtual long UserID { get; set; } // Foreign key in the DB
}
What exactly should my mapping look like?
How can I query the DB properly with either Lazy or Eager loading to be able to do this:
// user object instantiated using your provided example:
userObject.ExtendedDetails.Firstname
I feel like an idiot.. normally I can follow documentation but its very vague with this sort of usage. Can anyone point me to a proper example (or give one)?
I’m using the latest Fluent NHibernate straight from the Fluent NHibernate website.
Regards,
chem
Here is a good walk through that can help you get up and running: http://dotnetslackers.com/articles/ado_net/Your-very-first-NHibernate-application-Part-1.aspx
Your mappings would look something like this. Note, that I’m making some assumptions on that how you would like to generate your identities along with the type of mapping between these entities.
In order to query your relational data you will need to open a session within nhibernate. I generally create a helper along the lines of this.
From there you could directly query like this:
Note, that I’m leaving a lot out of this but hopefully this will assist you in getting up and running.