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 3627864
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T23:56:33+00:00 2026-05-18T23:56:33+00:00

I get a ModelValidationException (at the bottom) when working with EF-Code First. It wants

  • 0

I get a ModelValidationException (at the bottom) when working with “EF-Code First”. It wants me to define a Key but I’m not sure what exactly it means…

public class Unit
{
    Guid id;
    String public_id;
    String name;        
    bool deleted;
}

public class MyDataContext : DbContext
{
    public DbSet<Unit> Units { get; set; }

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<Unit>().ToTable("sometable");
    }
}

[TestFixture]
public class DataTests
{
    [Test]
    public void Test()
    {
        MyDataContext database = new MyDataContext();
        var o = database.Units;


        Console.WriteLine(o.Count()); // This line throws!
        Assert.IsTrue(true);
    }
}

System.Data.Entity.ModelConfiguration.ModelValidationException : One or more validation errors were detected during model generation:

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

System.Data.Edm.EdmEntitySet: EntityType: The EntitySet Units is based on type Unit that has no keys defined.

  • 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-18T23:56:34+00:00Added an answer on May 18, 2026 at 11:56 pm

    You need to use properties, not private local variables for all the fields that you want EF to create database fields for.

    Public Guid Id {get; set;}

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

Sidebar

Related Questions

We get the following error; The request was aborted: Could not create SSL/TLS secure
Get this simple python code, same matching with re.compile instance. I noticed that even
Get error 'ClassLibrary3.Class1.a' is a 'property' but is used like a 'type' when i
// GET: /Product/Delete/5 public ActionResult Delete(int id) { var res = (from r in
Get an empty HTML, type in this and see its source code on Google
// get friends public Cursor getFriends(){ Cursor c = dataBase.query(SqConstants.FRIENDS_TABLE_LOCAL, null, null, null, null,
Get User Action [HttpGet] [ActionName(Index)] public ActionResult Get(int id) { User u = UserCore.GetUser(id);
I get some doubts about behavior of this code : dispatch_async(queue, ^{ sleep(2); NSLog(@step1);
//get var of posted info so user does not //have to reinsert if if
Get message: OK, but incomplete or skipped tests! without any information where is happen.

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.