I have two tables in my database that I am trying to create for Linq2Sql objects. There they have more than that, but in essence they come down to:
Rooms UserActivity
-------- --------
RoomID ActivityID
RoomID (foreign key on Rooms.RoomID)
The UserActivity table is, in fact, only a log of actions that the user performs against the "Rooms" table.
Since the UserActivity table UserActivity used only for logging the actions taken, it made little sense for me (at least for me) to create the primary key for the table initially, until the Linq2Sql developer refused to make the UserActivity part of the Room object in my Linq objects. When I set up the objects in the designer of Visual Studio, I received the following 2 warnings:
Warning 1 DBML1062: The Type attribute 'UserActivity' of the Association element 'Room_UserActivity' of the Type element 'Room' does not have a primary key. No code will be generated for the association.Warning 2 DBML1011: The Type element 'UserActivity' contains the Association element 'Room_UserActivity' but does not have a primary key. No code will be generated for the association.
These warnings led me to create an ActivityID column in my table, as shown above.
I would like to know if there is a way to allow Linq2Sql to create relationships between my objects without a primary key in both tables. If I do not have a primary key in the UserActivity table, objects can still be created, but relationships are not generated.
Is it possible to do this, or should I try to make sure that my tables always have a primary key in them as a general good practice?
source share