Light Switch - Design pattern for multiple company application
-
Tuesday, August 21, 2012 10:32 AM
I would like to develop an application that provide the multiple company feature.
Each company uses a same database content and same database structure.
Each user will see the data only their company.
So I will create a company table, related to all tables, for saparate the company data.
But the user table will be automatically generated by LightSwitch, so I cannot make a relation
between user table and company table.
Can I handle it?
All Replies
-
Tuesday, August 21, 2012 2:55 PM
It is a good practice to have an "ApplicationUser" table in your application in which you have a weak reference to the real user (the one known in the membership provider) and in which you store additional info (like as you mention: company).
How you maintain that table depends on your specific situation. In most cases ApplicationUsers will be linked to lightSwitch users by an admin, but other mechanisms are possible
The main advantage of the ApplicationUser entity is that you can link other entities (like orders, etc. ) to an applicationUser (e.g. "ManagedBy" in the case of orders) with full database relational integrity. This gives you the full freedom to cope with the fact that in a company, people come and go. If an employee (i.e. an ApplicationUser) leaves the company, you can re-assign his linked entities to another employee.
Furthermore, you can easily apply row level security (e.g. an user can only see entities related to own entity).
paul van bladel
- Edited by Paul Van Bladel Tuesday, August 21, 2012 2:56 PM
- Marked As Answer by Dino HeModerator Monday, August 27, 2012 1:04 PM
-
Tuesday, August 21, 2012 4:26 PM
For this type of multi-tenant deal, you typically will want to look hard at the new feature in 2012 call Entity Set Filters. So you have a Users tables which holds the Forms username. This is how you map current authenticated Username to a Users table record. Your Users table will have a one-to-many between Company table and Users. A company can have many users, a user must be member of one company. You can filter based on company data. Beth has a post on using this feature.
- Proposed As Answer by Babloo1436 Tuesday, August 21, 2012 4:30 PM

