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 Tokens.

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

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])

asked Aug 17, 2015 in .net by rajesh
0 votes

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.