Fluent Nhibernate AutoMapping — 2 foreign keys to same table?

后端 未结 1 1890
清酒与你
清酒与你 2021-01-21 15:14

Let say I\'m doing a basic transaction system where I have the following objects.

public class User
{
   public virtual int Id{get; set;}
}

public class Transac         


        
相关标签:
1条回答
  • 2021-01-21 16:07

    Yarg!

    I finally figured it out when doing the auto mapping you have to specify an override with two separate Has Many mappings

       return Fluently.Configure()
        .Database(persistenceConfigurer)
        .Mappings(m => m.AutoMappings.Add(
            AutoMap.AssemblyOf<User>()
                .Override<User>(map=> map.HasMany(user=> user.Transactions).KeyColumn("Buyer_id"))
                .Override<User>(map => map.HasMany(user => user.Transactions).KeyColumn("Seller_id"))                
            ))
        .ExposeConfiguration(BuildSchema)
        .BuildSessionFactory();
    
    0 讨论(0)
提交回复
热议问题