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

  • SEARCH
  • Home
  • 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 7559613
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T12:40:50+00:00 2026-05-30T12:40:50+00:00

I am getting following error while using POCO entity width EF One or more

  • 0

I am getting following error while using POCO entity width EF

One or more validation errors were detected during model generation:
System.Data.Edm.EdmEntityType: : EntityType ‘Brand’ has no key
defined. Define the key for this EntityType.
System.Data.Edm.EdmEntitySet: EntityType: EntitySet ‘Brand’ is based
on type ‘Brand’ that has no keys defined.

POCO

public class Brand
    {
         //[Key]
        public int BrandId { get; set; }
        public String BrandName { get; set; }
        public String CompanyName { get; set; }
        public Int32 CountryId { get; set; }
        public String Description { get; set; }
    }

DBConetxt

  public class DBContext : DbContext
    {
        public DBContext()
            : base("DBContext")
        { }


        public DbSet<Brand> Brand { get; set; }
        public DbSet<Country> Country { get; set; }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Entity<Brand>().ToTable("dbo.Brand");
            modelBuilder.Entity<Country>().ToTable("dbo.Country");
            base.OnModelCreating(modelBuilder);
        }
    }

DB Table

BrandId int
BrandName   varchar
CompanyName varchar
CountryId   int
Description varchar
CreatedBy   int
CreatedDate datetime
ModifiedBy  int
ModifiedDate    datetime

uses

DBContext o = new DBContext();
return o.Brand.ToList();

If [Key] annotation is used with POCO to indicate pk then it works fine but I don’t want to use any dependency class with POCO.

Any suggestions???

Thanks

  • 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-30T12:40:51+00:00Added an answer on May 30, 2026 at 12:40 pm

    You can configure the PK using the fluent API. You don’t have to explicitly specify the database schema as dbo.

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Entity<Brand>().ToTable("Brand");
            modelBuilder.Entity<Brand>().HasKey(b => b.BrandId);
    
            modelBuilder.Entity<Country>().ToTable("Country");
            base.OnModelCreating(modelBuilder);
        }
    

    You can also define a navigational property Country on Brand POCO.

    public class Brand
    {
        public int BrandId { get; set; }
        public String BrandName { get; set; }
        public String CompanyName { get; set; }
        public Int32 CountryId { get; set; }
    
        public virtual Country Country {get; set; }
    
        public String Description { get; set; }
    }
    

    Action method

        public ActionResult Create()
        {
            ViewData["Countries"] = new SelectList(db.Country.ToList(), 
                   "CountryId", "CountryName");
    
            return View();
        }
    

    Then in view

    @Html.DropDownListFor(model => model.CountryId, 
              (IEnumerable<SelectListItem>)ViewData["Countries"], "-")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am getting following error while building my vc++ project (Using visual studio 2010)
while using tiles along with spring i m getting following error: java.net.UnknownHostException: tiles.apache.org program
I'm getting the following error while running the android application. Currently i'm using Windows
While compiling the c++ code using android NDK I am getting the following error:
I am using Visual Studio 2005. While debugging code I am getting following error
I'm getting the following error while validating an xml document while using IXMLDOMDocument2 (C++):
I am getting the following error while using a sample code of FBConnect. Earlier
I am getting following error while executing a unti test case(JUNIT).I am using it
I am getting the following error while compiling a sample program in Qt 4.5
I am getting the following error while running my MVC application, which uses the

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.