I assume you have read the documentation?

https://github.com/jagregory/fluent-nhibernate/wiki/Fluent-mapping

Also, I would consider using the Unit-of-Work pattern instead of newing up 
an ISession for each action.

On Wednesday, August 21, 2013 9:59:28 PM UTC+2, ni...@customapp.co.za wrote:
>
> Would appreciate a push in the right direction.  All the following have an 
> Id and some members not relevant.
>
> An *Inspection *have 1 *License*, but I don't want a *License *to have an 
> *Inspection *property.  
> An *Inspection *have 0 to many *Damages *(and each *Damage *will only 
> belong to one *Inspection*)
>
> Before going on, if the following is too much trouble to read, a nice 
> article on this specific kind of relationship will be more than enough. 
> Just need a push in the right direction since this is urgent and (know 
> sound wrong) don't have time right now learning FluentNHibernate inside out.
>
> So my models is as follows
>
>> public class Inspection
>> {
>> public Inspection() {
>> Damages = new List<Damage>();
>> }
>>
>>  public virtual int Id { get; protected set; }
>>  // ... left out irrelevant members that map just fine
>> public virtual License License { get; set; }
>> public virtual IList<Damage> Damages { get; protected set; }
>> }
>> public class License {
>> public virtual int Id { get; protected set; }
>>  // ... left out irrelevant members that map just fine
>> }
>> public class Damage  {
>> public virtual int Id { get; protected set; }
>>  // ... left out irrelevant members that map just fine
>> public virtual Inspection Inspection {get; set; }
>> }
>>
>>
> Now, obviously I don't know enough yet and doing my mappings wrong, but 
> this is basically what I got right now (btw, pseudo code, so might have 
> made a typo or two):
>
> public class InspectionMap : ClassMap<Inspection>
>> {
>> public InspectionMap()
>> {
>> Table("Inspections");
>> Id(x => x.Id);
>>  // ... left out irrelevant members that map just fine
>>  References(x => x.License).Cascade.All().Column("LicenseId");
>>  HasMany(x => x.Damages)
>>                 .Cascade.All()
>>                 .Inverse();
>> }
>> }
>
>
> For instance if I create an "Inspection" without the "License" set, it 
> save fine.
> If I add a "License" to an existing "Inspection" it also save fine.
> But if I get an "Inspection", change the "License" and then update the 
> "Inspection" it will create a new "License"
>
> Not sure what else is relevant?  Here's some of my repository methods, for 
> in case that matter:
>
>> public Inspection Get(int id)
>> {
>> using (ISession session = NHibernateHelper.OpenSession())
>> return session.Get<Inspection>(id);
>> }
>> public void Save(Inspection inspection)
>> {
>> using (ISession session = NHibernateHelper.OpenSession())
>> using (ITransaction transaction = session.BeginTransaction())
>> {
>> session.Save(innspection);
>> transaction.Commit();
>> }
>> }
>> public void Update(Inspection innspection)
>> {
>> using (ISession session = NHibernateHelper.OpenSession())
>> using (ITransaction transaction = session.BeginTransaction())
>> {
>> session.Update(inspection);
>> transaction.Commit();
>> }
>> } 
>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"Fluent NHibernate" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to fluent-nhibernate+unsubscr...@googlegroups.com.
To post to this group, send email to fluent-nhibernate@googlegroups.com.
Visit this group at http://groups.google.com/group/fluent-nhibernate.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to