Using C#4.0
Following on from my question How to configure nHibernate for many-many mapping? I’m getting confused and it may be because my class design is wrong.
A Market models a financial market. A Broker models a financial broker who can interact with many markets. A Market can interact with many Brokers. See the Broker and Market classes below.
public class Market
{
public int Id { get; set; }
public string Symbol { get; set; }
public string Description { get; set; }
}
public class Broker
{
public int Id { get; set; }
public string Name { get; set; }
public bool IsDefault { get; set; }
public bool IsActive { get; set; }
public IList<Account> Accounts { get; set; }
}
I have an extra attribute in the many-to-many relationship called MinIncrement that is unique to a Market and a Broker combination.
What’s the best way to model this? Do I need to create a third class or can I put MinIncrement in one of my existing classes? Should I create a third class and inherit from one of my existing ones? I’m not really sure how to model this in an OO way.
In my database it’s easy. I have three tables:
- brokers (PK: brokerId)
- markets (PK: marketId)
- brokerMarkets (PK: brokerId, marketId), MinIncrement column goes in here
Yes, I would create a third entity: