Getting a few projects started with EF, but I had some questions about join tables and keys etc. Lets say I have a table of applications and a table of permissions. Applications have many permissions and each permission can belong to many applications (many-to-many).
Now, the Application and Permission tables are easy:
Applications
--------------
PK ApplicationID
Name
Permissions
--------------
PK PermissionID
Name
But what's the BEST way to do the join table? I have these two
options:
ApplicationPermissions
-----------------------
PK ApplicationPermissionID
CU ApplicationID
CU PermissionID
OR
ApplicationPermissions
-----------------------
CPK ApplicationID
CPK PermissionID
PK = Primary Key
CPK = Composite Primary Key
CU = Composite Unique Index
Have you ever been burned doing it one way over the other? is it
strictly preference? It has occurred to me that a lot of the
"differences" will be abstracted away by my repository pattern (for
example, i would almost never create an entire permission object
and add it to an application, but do it by ID or unique name or
something), but I guess I'm looking for horror stories, one way or
the other.
I believe you mean "junction" table, not "join" table.
There is no need for a junction table to have it's own ID field. You would never need to join or filter on such an ID. You would only join or filter on the ID's of the tables you're mapping. An ID on a junction table is a waste of disk space.
So the "best" option is to avoid the ID. Typically a junction table will have 2 covering indexes. Each covering index using one of the mapped ID's as the primary sort field.
But "best" is not by a long shot. It's a very minor issue to have a redundant ID field. You will not have any horror stories over a small amount of wasted disk. The ID won't "steal" the clustered index because you don't want to cluster on the mapped combo anyway.
If your framework wants all tables to have an ID, then go for it. If your team's database standards dictate all tables must have an ID then go for it. If not, then avoid it.
Getting a few projects started with EF, but I had some questions about join tables and...
SQL Query Question: I have a database with the tables below, data has also been aded into these tables, I have 2 tasks: 1. Add a column to a relational table POSITIONS to store information about the total number of skills needed by each advertised position. A name of the column is up to you. Assume that no more than 9 skills are needed for each position. Next, use a single UPDATE statement to set the values in the new...
Please answer this questions as required
I couldn't delete the old pic so the new one is butter
and for the same question.
RealGree uses the paper form as below to record the weekly (just one week in this 5. A lawn and tree care company ion) informati application to keep track of the information of the part-time employees. Please (a) develop the E-R diagram (8 points). ion about is part-time employees (one form for one employee). The company asks...
Please read the article and answer about questions. You and the Law Business and law are inseparable. For B-Money, the two predictably merged when he was negotiat- ing a deal for his tracks. At other times, the merger is unpredictable, like when your business faces an unexpected auto accident, product recall, or government regulation change. In either type of situation, when business owners know the law, they can better protect themselves and sometimes even avoid the problems completely. This chapter...
I have this case study to solve. i want to ask which
type of case study in this like problem, evaluation or decision? if
its decision then what are the criterias and all?
Stardust Petroleum Sendirian Berhad: how to inculcate the pro-active safety culture? Farzana Quoquab, Nomahaza Mahadi, Taram Satiraksa Wan Abdullah and Jihad Mohammad Coming together is a beginning; keeping together is progress; working together is success. - Henry Ford The beginning Stardust was established in 2013 as a...