Hi guys,

I am sure this is a simple fix, but I cannot figure it out for the life in 
me! I need some help, been looking for answers but can't find any : (
I am using NHibernate 3.3 and mapping using the sexy Mapping-by-code 
feature. 

I have two tables: 

*CustomerAccount *
BSB (PK)
Acct_Number (PK)
Name
Type

*PendingTransactions*
Cust_BSB (PK, FK)
Cust_Acct_Number (PK, FK)
Amount

I want to map the one to many relationship here, but I can't figure out how 
to do the mapping or specify the multiple foreign key columns in the 
PendingTransactions table.

public class CustomerAccount
{
    public virtual CustomerAccountKey Key { get; set; }
    public virtual string Name { get; set; }
    public virtual string Type { get; set; }

    public virtual ICollection<PendingTransaction> PendingTransactions { 
get; set; }
}

public class CustomerAccountKey
{
    public virtual String BSB { get; set; }
    public virtual String Acct_Number { get; set; }

    public override bool Equals(object obj)
    {
        var t = obj as CustomerAccountKey ;
        return (t != null) &&
                (String.Compare(BSB, t.BSB, true) == 0) && 
                (String.Compare(Acct_Number, t.Acct_Number, true) == 0);
    }
    public override int GetHashCode()
    {
        return (string.Format("{0}{1}", new object[] { 
BSB, Acct_Number})).GetHashCode();
    }
}

public class CustomerAccountMap : ClassMapping<CustomerAccount>
{
   public CustomerAccountMap()
    {
        Table("CustomerAccount");       
        ComponentAsId(i => i.Key, map => {
             map.Property(p => p.BSB);
             map.Property(p => p.Acct_Number);
        });
        Property(i => i.Name);
        Property(i => i.Type);
      
        //Is this mapping of the relationship correct??
        Bag(x => x.PendingTransactions, collectionMapping =>
                            {
                                collectionMapping.Key(????);
                                collectionMapping.Inverse(true);
                                
collectionMapping.Cascade(Cascade.DeleteOrphans);
                            },
                            r => r.OneToMany());
    }
}

public class PendingTransactionEntity
{   
    public virtual CustomerAccount Account { get; set; }
    public virtual int Amount { get; set; }
}

public class PendingTransactionMap : ClassMapping<PendingTransactionEntity>
{
        public PendingTransactionMap()
        {
            Table("PendingTransaction");
            
            //How do I map the ids when they are the foreign keys and also 
map the relationship here??

            Property(i => i.Amount);
        }*
*
}
*
*
*How do I do the mappings (with components preferably)?*
*
*
Please tell me it is possible! I have a more complicated extended version 
of this problem as well, involving a third table, 
which is mapped to the pendingtransactions table which has a composite key 
composed of 3 columns. 

Prabu
*
*
*
*
*
*

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/nhusers/-/wqs0X6cYih8J.
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/nhusers?hl=en.

Reply via email to