Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dbcontext scaffold - tables without primary key defined #5913

Closed
12michel34 opened this issue Jun 30, 2016 · 18 comments
Closed

dbcontext scaffold - tables without primary key defined #5913

12michel34 opened this issue Jun 30, 2016 · 18 comments

Comments

@12michel34
Copy link

I tried to scaffold a dbcontext from a database from a 3th party vendor. Unfortunately the tables of this database have no primary key explicit defined. The scaffold command fails with:

Unable to identify the primary key for table 'abc'.
Unable to generate entity type for table 'abc'.

In the past we have connected to the database with edmx data-model and there was no problem. Is it possible to scaffold without primary key or to set a option on the command wich defines the primary key field?

@rowanmiller
Copy link
Contributor

Currently it is not supported. We would be tackling the ability to scaffold something without a key as part of #1679 (I realize your scenario is a table without a key, but it would be covered by that feature). In the meantime, you would need exclude that table from the reverse engineer, and then manually add the entity and specify the properties that EF should use as the key.

@hubert17
Copy link

It's March 2018.
https://stackoverflow.com/questions/39701068/scaffold-dbcontext-creating-model-for-table-without-a-primary-key

@talsuk5
Copy link

talsuk5 commented Aug 15, 2018

@hubert17 , you're wrong, it's August 2018 😂
two years and counting?

@boris008
Copy link

So is there any solution for this problem?

@divega
Copy link
Contributor

divega commented Aug 30, 2018

@boris008 this issue was closed a long time ago, but we are tracking reverse engineering of views into query types in #1679 for EF Core 2.2. We can consider reverse engineering tables without primary keys in a similar fashion. cc @bricelam

@bricelam
Copy link
Contributor

Yes, I was going to tackle #5719 at the same time.

@darkguy2008
Copy link

I'm facing the same issue, just got my project blocked due to this...

@KaeTar
Copy link

KaeTar commented Oct 11, 2018

Just need it to actually generate the model and throw a //TODO: in there indicating the need to define a key. I am fine with it throwing an error still if you try to use a class that doesn't define the key. But I am tired of hand creating models so I can manually define the key using attributes, it would be nice if the model existed so I could add the key attributes

@Elbeaux
Copy link

Elbeaux commented Oct 16, 2018

Just need it to actually generate the model and throw a //TODO: in there indicating the need to define a key. I am fine with it throwing an error still if you try to use a class that doesn't define the key. But I am tired of hand creating models so I can manually define the key using attributes, it would be nice if the model existed so I could add the key attributes

I agree!

@eltiare
Copy link

eltiare commented Oct 25, 2018

I'm really not looking forward to generating dozens of 50+ tables by hand, many of which do not have primary keys defined. :(

@sirobert
Copy link

What is the status of it?

@ajcvickers
Copy link
Member

@sirobert It's closed. See comments above.

@boris008
Copy link

And solution? I need scaffold model from database structure and tables has no primary keys.

@OUANGDRAK78
Copy link

Up, same for me...

@asinesi
Copy link

asinesi commented Feb 25, 2019

Up, same for me....

@bricelam
Copy link
Contributor

Note, this issues was closed as a duplicate of #5719

@rbonomo
Copy link

rbonomo commented Aug 8, 2019

You folks over at [redacted] should really focus more on your customers and their needs.

Note: @ajcvickers edited this comment to remove content that violated the project’s code of conduct.

@rodiaua
Copy link

rodiaua commented Mar 11, 2020

Currently it is not supported. We would be tackling the ability to scaffold something without a key as part of #1679 (I realize your scenario is a table without a key, but it would be covered by that feature). In the meantime, you would need exclude that table from the reverse engineer, and then manually add the entity and specify the properties that EF should use as the key.

How can we exclude the table from the reverse engineer?

@ajcvickers ajcvickers reopened this Oct 16, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests