0

I have a database at work that has tables without primary keys (Sql Server). It uses a different schema. It has a unique (sometimes compound) key for each table. I cannot modify database in any way. It is a vendor's database.

Is it ok to trick EF into thinking the unique key is the primary key? Will there be any issues with inserting or updating records?

Thanks,

Rick

Rick Rat
  • 1,732
  • 1
  • 16
  • 32
  • I mean, instead of declaring this an Index can I declare this as the primary key? This must have been the database developers intention for these tables. – Rick Rat Oct 10 '16 at 14:16
  • are you saying that neither the possibility of defining composed PKs (https://ef.readthedocs.io/en/latest/modeling/keys.html) or alternate keys (https://ef.readthedocs.io/en/latest/modeling/alternate-keys.html) will help and you are looking for a different solution? Also just a quick catch-up for you, EF7 was renamed to EF Core :) – Julie Lerman Oct 10 '16 at 14:24
  • I cannot modify the database. They have a convention for their unique index as a fake primary key. – Rick Rat Oct 10 '16 at 14:27
  • Also cannot use alternate key because alt keys are in conjunction with a primary key – Rick Rat Oct 10 '16 at 14:28
  • @JulieLerman I do want to use the fluent key was wondering if there is issues using it that way with a unique index instead of an actual key – Rick Rat Oct 10 '16 at 14:30
  • Did you try scaffolding the dbcontext (reverse engineer) ? – ErikEJ Oct 10 '16 at 15:37
  • @ErikEJ yes does not scaffold those tables – Rick Rat Oct 10 '16 at 15:58

0 Answers0