1

My first time working on a project solo, and first time attempting to scaffold models from an existing DB. Please see attached pictures for the error.

Scaffold-DbContext "Server=.\SAPAS_LOCAL_TEST;Database=SAPAS_TEST;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models

Build started... Build succeeded.

The key {'YearId'} cannot be added to keyless type 'TlkupYear'.

See the screenshot below:

enter image description here

I've noticed that in the DB this table has no keys, only values... Any way to work around this issue?

Let me know how I can work around this.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Vik
  • 126
  • 5

1 Answers1

1

Never mind, I figured it out, the table didn't have a PrimaryKey set. Easy fix once I figured that out.

ALTER TABLE TABLENAME ADD PRIMARY KEY(COLUMN_NAME)

did the trick for me

Vik
  • 126
  • 5