Linq-To-SQL Association with Multiple Foreign Keys Problem?

Some schools and books teach to use "Composite Primary Keys", but in reality, they are not a good idea. Many software does not allow these fields, and even if it does, it's difficult to handle Is always better to use a single field primary key My suggestion, is to keep those fields as standard fields, or foreign keys, an add a new field that is assigned or incremented automatically Example: Table Name="Screen.

Some schools and books teach to use "Composite Primary Keys", but in reality, they are not a good idea. Many software does not allow these fields, and even if it does, it's difficult to handle.Is always better to use a single field primary key. My suggestion, is to keep those fields as standard fields, or foreign keys, an add a new field, that is assigned or incremented automatically.

Example.

I wasn't the original author of the database and this is how the database was written. I had hoped not to do this because it's simpler and more intuitive to let multiple foreign keys define a objects. If I haven't heard any more replies by Monday I'll give it a shot though.

– Temp__User Jan 7 at 22:35 It is not a bad idea to use composite primary keys when when both values are immutable and define uniqueness of the row, and to state otherwise is just bad advice. If an ORM solution can't handle composite primary keys, it's a deficiency of the ORM solution. We should not be modeling our data to fit the constraints of an ORM.

– w. Brian Aug 21 at 1:08.

Sice I've been struggling with something similar and this question came close to mine, I'll add my 2 cents here for the next soul that might come by with the same problem (creating the database at runtime from the object model). If your composite key doesn't really have to be a primary key (i.e. You just want to provide uniqueness of the combination) the solution is to: add a regular primary key (integer identity db generated column) that you will reference from the foreign key.

Provide uniqueness constraint with an additional step on your DataContext, e.g. : yourDataContext. ExecuteCommand("ALTER TABLE Stuff ADD UNIQUE (unique_thing_1, unique_thing_2, unique_thihng_3)"); afterwards submits will throw an exception when attempting to insert duplicate fields.

For example; let's say you have a Users table and a Roles table. Users have many roles, and roles have many users.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions