asp.net - Should I use a composite key for a map table, which is also used for a foreign key? -
I am using ASP.NET and entity framework to create a website. There is currently a map table for many relationships between me ... let's say that the user and the soccer team are:
Users
Teams
Username
Part 1 : Is it the best practice to use a composite key for the primary key in the map table? In other words:
User Ton table PK UserId
PK TeamId
PreferenceId
Part 2 : The warning is that there is my second table too. Let's call it "UserTeamPredictions", which stores user's predictions for a team for each year. In that table there is a foreign key that points back to the map table. So something looks like:
UserTeamPredictions table
PK UserTeamPredictionId FK UserId
< Strong> FK TeamId
Predictive Forecast Year
This unit works fine in the framework, however, there are some problems when I refer to relationships under third party control Telerik Even if this ideal data is not setup, should I change the table structure / relationships so that it is easy to work in code with data binding and other things?
The change must be added to the UserTem Map table, the integer primary key, which allows the userTemplates to be in the context of the straight key, because instead of its overall key:
UserTame Table
PK UserTeamId
FK UserId
FK TeamId
PreferentId
UserTeamPredictions Table
PK UserTeamPredictionId FK Strong> UserTeamId
Predictive forecast
What do you think ?!
I do not want to use a rental key and a unique index on the UserId and TeamId columns Will keep When I'm more than two, instead of mixing whole and surrogate keys, I actually get sick, then I choose to go with all the surrogates, wherever possible, meaningless auto-matching kunge.
This is a bonus to give you a good performance when you join it, and that means that without knowing the schema, you always know the keys to a given table (table name + ID), some ORM tools are only composite Work properly with single column instead of key.
Comments
Post a Comment