Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
676 views
in Technique[技术] by (71.8m points)

entity framework - Error 6002: The table/view does not have a primary key defined

I am getting a couple of these errors that make perfect sense as they are on views. I understand what they mean, however I am looking for a way to prevent that warning message from being generated with the model. I thought I could edit the .edmx XML to remove the errors but the warnings get regenerated. I have a key defined on the views although it doesn't seem to have helped.

Any way to get rid of these warnings? Or is there someway to have the Entity Framework realize that this is not an editable table and that is doesn't need a primary key? I'm asking mostly from a project aesthetics point-of-view (I don't like seeing warnings in my Error List).

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I perfectly understand where you're coming from. This is one of the biggest annoyances I've had to deal with when trying to get to grips with the EF and, apparently, it's a very common issue.

The solution that worked for me was to open the EDMX with the view in designer mode and assign a primary key myself. It doesn't matter really what it is, as long as there is one. You right-click on the column you want to set as primary key and select Entity Key (it's a checkbox option). You may have to exit and restart Visual Studio until this warning decides to go away.

I hope it works for you too. But even if it does, it's a short-term fix, as the next time you update your view, it will probably have the same problem. But as long as the above steps work, it should take just seconds to fix.

Also, here's some links you might find useful:


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...