0

I have a Shop table, a StaffRole table, and a ShopStaffRole table that serves as many-to-many, but with additional fields like IsRequired, etc.

Shop
  ShopId
  ShopName
  ShopAddress

StaffRole
  StaffRoleId
  StaffRoleName

ShopStaffRole
  ShopStaffRoleId
  ShopId
  StaffRoleId
  IsRequired

So my choices seem to be a Shop class and a StaffRole class with NHibernate many-to-many mapping between them, but that won't map IsRequired well in my object model, so it makes sense to have a ShopStaffRole class as well, and one-to-many mappings between it and both Shop and StaffRole.

However, upon closer inspection, the StaffRole table has only an Id and a Name. Would it make sense to just use an NHibernate join to put the StaffRoleName directly into the ShopStaffRole class as a string, and do away with representing the StaffRole table as a class altogether?

I don't anticipate the StaffRoleName changing within this application, so I should be able to get away with a read-only mapping that prevents one ShopStaffRole from affecting others with the same StaffRoleName.

Does this make sense, or am I missing something? It feels like my object model is just aping my relational model, table by table.

mo.
  • 4,165
  • 3
  • 34
  • 45
  • Please provide your mappings and your entities. There are several ways you could go about querying this. QueryOver, Criteria Api, HQL, Linq. – CrazyCoderz Feb 10 '12 at 15:21
  • Hi, my question isn't about querying an existing ORM, it's about considerations while deciding upon the ORM. There are no mappings or entities yet, just the tables mentioned above. – mo. Feb 10 '12 at 22:32

2 Answers2

1

As long as the redundancy isn't your biggest concern and you're not going to add any interface to manage roles later then you're good to go with the Join approach.

Denis Ivin
  • 5,594
  • 1
  • 26
  • 25
0

As it turns out, I sort of answered my own question. I can't say it's never a good idea to do this, but I feel now like there are so many potential gotchas that it's extremely unlikely to be worthwhile.

In my case, I realised that although this application wouldn't have to worry about StaffRole changing, there would be another table that found its way into the scope later on that referenced StaffRole as well, so if we ever wanted to look up a StaffRole of a Shop, then look up all the training material required by this StaffRole, then it would be a good way to have two-way accessors between StaffRole-ShopStaffRole, and StaffRole-TrainingStaffRole.

mo.
  • 4,165
  • 3
  • 34
  • 45