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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T09:06:04+00:00 2026-06-08T09:06:04+00:00

Busy learning MVC 3 and EF … I have an existing database, I then

  • 0

Busy learning MVC 3 and EF …

I have an existing database, I then create my Model aligned to my DB Table (Agency):

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity;
using System.ComponentModel.DataAnnotations;

namespace Dataset_Test.Models
{
    public class Agency
    {

        public int AgencyID { get; set; }
        [Required(ErrorMessage="Give me a name.")]
        [StringLength(5)]
        [MinLength(2)]
        public string AgencyName { get; set; }

    }

}

My DAL class:

public class DBContext: DbContext
    {
        public DbSet<Person> Persons { get; set; }
        public DbSet<Agency> Agency { get; set; }
    }

After using the controller generator popup to create the controller and views and then running the code:

private DBContext db = new DBContext();

        //
        // GET: /Agency/

        public ViewResult Index()
        {
            return View(db.Agency.ToList());
        }

I get an error which it simply cant find the Table as EF is automatically looking for the Table (dbo.Agencies) yet I have declared my Model Class as Agency, my question is how and where do you set the Table Name reference that the Model should be linked to, i.e. it should look for dbo.Agency and NOT dbo.Agencies?

Layout:
enter image description here

  • 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-06-08T09:06:06+00:00Added an answer on June 8, 2026 at 9:06 am

    You need to add a

    [Table("Agency")]
    

    attribute to your Agency class

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

Sidebar

Related Questions

I am busy climbing the learning curve for OpenGL, using Delphi (pascal); I am
I´m busy converting an existing project from an Ant build to one using Maven.
I am busy working with an ASP.NET MVC 3 application and using Windows 7.
Busy learning Ruby... the documentation have an example: hello world.count(lo, o) that return 2
I am busy learning ASP.Net MVC and so I recently installed MVC 4 on
I am busy with a task and i have to create a structure and
I'm busy working on a windows phone application that calls a servlet that then
I am busy converting a query using the old style syntax to the new
I am busy recreating a powerpoint with xml. i have added all the neccessary
I am busy writing my own collection type and need to have a function

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.