Ask a Question
Advertise on boostr.in
Organizational Research By
Surprising Reserch Topic
Why foreign key related table rows/entities are ICollection?
I have an Accounts table that stores id, username and password (some others things too but they're not necessary).
I also have a Tokens table and its id field is a foreign key to Accounts table's id field.
If I create a CodeFirst EF Data Model, Account class (not AccountsModel) stores Token class in ICollection like ICollection
Why? I can only have single Token for Account (because of id), so shouldn't it be Token Token property (instead of ICollection)?
Here is the CREATE script for the two tables:
CREATE TABLE [dbo].[Accounts] (
¬†¬†¬†¬†[Id] ¬†¬†¬†¬†¬†¬†¬†INT ¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†IDENTITY (1, 1) NOT NULL,
¬†¬†¬†¬†[Username] ¬†VARCHAR (16) ¬†NOT NULL,
¬†¬†¬†¬†[Password] ¬†CHAR (32) ¬†¬†¬†¬†NOT NULL
¬†¬†¬†¬†CONSTRAINT [PK_Accounts] PRIMARY KEY CLUSTERED ([Id] ASC)
CREATE TABLE [dbo].[Tokens] (
¬†¬†¬†¬†[Id] ¬†¬†¬†¬†¬†¬†¬†¬†INT ¬†¬†¬†¬†¬†¬†NOT NULL,
¬†¬†¬†¬†[Activation] CHAR (32) NOT NULL
¬†¬†¬†¬†CONSTRAINT [FK_Tokens_To_Accounts] FOREIGN KEY ([Id]) REFERENCES [dbo].[Accounts] ([Id])
Aug 17, 2015
to add a comment.
Related Hot Questions
Your name to display (optional):
Email me at this address if my answer is selected or commented on:
Email me if my answer is selected or commented on
Privacy: Your email address will only be used for sending these notifications.
To avoid this verification in future, please