Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5983455
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T22:14:00+00:00 2026-05-22T22:14:00+00:00

I have a existing DB and I use the approach DB First with Entity

  • 0

I have a existing DB and I use the approach “DB First” with Entity Framework 4.1. Unfortunately, the DB is using some legacy naming conventions so that the columns with primary keys often use various names such as “occID”. Later on during validation the EntityFramework throws an exception when validating the entity model saying that

System.Data.Edm.EdmEntityType: : EntityType ‘Occupancy’ has no key defined. Define the key for this EntityType.

This entity has a unique key (and it is also marked as EntityKey in the Edmx model), but the model validator keeps complaining. The only solution I found is to sign the property in the generated DbContext class with the data annotation [Key] so that EF knows which property is a key.

Are there other ways to do that? I suppose that EF is checking some coding conventions to recognize which property is a Key. Since this is not a code-first approach, I am not allowed to change the generated code manually as the changes get lost everytime I change something in the model.

This is the corresponding part of the EDMX file:

 <EntityType Name="occupancy">
           <Key>
             <PropertyRef Name="occID" />
           </Key>
           <Property Name="occID" Type="int" Nullable="false"
 StoreGeneratedPattern="Identity" />
           <Property Name="occPDM" Type="int" />
           <Property Name="occDatePDM" Type="datetime" />
           <Property Name="occDatePC" Type="datetime" />
           <Property Name="occOccupancy" Type="int" />
           <Property Name="occSityControlID" Type="bigint"
 />
           <Property Name="occSityControlLine" Type="int"
 />
           <Property Name="occPDM_Id" Type="bigint" />
           <Property Name="occServiceCar" Type="int" />
           <Property Name="occMoneyCar" Type="int" />
           <Property Name="occPdmParentId" Type="int" />
         </EntityType>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T22:14:01+00:00Added an answer on May 22, 2026 at 10:14 pm

    Well, I solved this problem by removing all generated classes and generating them completely fom the beginning. Now the Entity Model contains corresponding keys and I do not need to modify the model manually.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When using the Entity Framework there are basically two ways to create your model.
We have an existing java-based heavyweight project that needed an interactive script interpreter. After
The whole story; I have some KeyValuePairs that I need to store in a
I'm designing some new class diagrams for extending an existing office automation application. In
I have an existing Ant project and would like to speed up the build
I am using Eclipse to develop an Android application that plots Bluetooth data. I
G'day everyone, I have a system (the source) that needs to notify another system
This is using jQuery 1.6.1 and Validate 1.8.1. I have been banging my head
I have an existing database with lots of complex stored procedure and I want
We have an existing big application which contains a lot of data. We'd like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.