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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:37:03+00:00 2026-05-28T02:37:03+00:00

I am using Entity Framework 4.1 code first to connect to an already existing

  • 0

I am using Entity Framework 4.1 code first to connect to an already existing database. The table that I am using first is called Bank. I also have a Bank class as my domain model. This is how I mapped my class and table:

public class HbfContext : DbContext
{
     public DbSet<Bank> Banks { get; set; }

     protected override void OnModelCreating(DbModelBuilder modelBuilder)
     {
          modelBuilder.Entity<Bank>().ToTable("Bank");
     }
}

My Bank table:

BankID INT
BankName VARCHAR(50)

My Bank class looks like this:

public class Bank
{
     public int Id { get; set; }
     public string Name { get; set; }
     public bool IsActive { get; set; }
}

I am having issues when I want to return all the banks. The SQL statement returned from:

return db.Banks
     .OrderBy(x => x.Name);

is:

SELECT
     [Extent1].[Id] AS [Id],
     [Extent1].[Name] AS [Name],
     [Extent1].[IsActive] AS [IsActive]
FROM
     [dbo].[Bank] AS [Extent1]
ORDER BY
     [Extent1].[Name] ASC

This is not going to work because my table does not have the Id, Name and IsActive columns. How would I fix this and would EF map BankId to Id and BankName to Name automatically?

  • 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-28T02:37:04+00:00Added an answer on May 28, 2026 at 2:37 am

    You need to instruct EF to ignore IsActive property and map other properties. If you don’t like data annotations you can do this with fluent API:

    modelBuilder.Entity<Bank>().Ignore(b => b.IsActive);
    modelBuilder.Entity<Bank>().Property(b => b.Id).HasColumnName("BankID");
    modelBuilder.Entity<Bank>().Property(b => b.Name).HasColumnName("BankName");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using Entity Framework Code First to create a database table. My model
I'm using Entity Framework Code First to generated my database, so I have an
I'm using Entity Framework Code-First with POCOs for my database interaction. I have a
I have been using Entity Framework CTP with Code-First as in this tutorial by
I am using Entity Framework Code First. I want to query entites from database
I am successfully creating database (SQL Ce) using Entity Framework Code First approach (C#-WPF).
I have a small MVC 3 app using Entity Framework Code First and use
Using the Entity Framework Code First paradigm I have defined the following objects and
When creating a database using Entity Framework code-first, a lot of the database model
I'm using Entity Framework code first to manage a database backstore for my users.

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.