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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T06:52:56+00:00 2026-06-14T06:52:56+00:00

I am new to Visual Studio MVC3 and trying to connect to a database.

  • 0

I am new to Visual Studio MVC3 and trying to connect to a database. I have my connection string in the web.config file:

add name=”con” connectionString=”Data Source=190.190.200.100,1433;Network Library=DBMSSOCN;Initial Catalog=myDataBase;
User ID=myUsername;Password=myPassword;” providerName=”System.Data.SqlClient”

However, the server has multiple tables. How/where will I specify which table to use when querying the database?

EDIT:
For example, I am looking at this example. How does the application differentiate between the tables to display data? When you call return View(db.Students.ToList()) as in the example in the link, how does the application know to look in the student table and not in the enrollment table?

  • 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-14T06:52:58+00:00Added an answer on June 14, 2026 at 6:52 am

    How does the application differentiate between the tables to display
    data? When you call return View(db.Students.ToList()) as in the
    example in the link, how does the application know to look in the
    student table and not in the enrollment table?

    The db.Students part comes from Entity Framework.

    Read the “Creating the Database Context” section in the link that you posted.
    You will find the following code there:

    using System;
    using System.Collections.Generic;
    using System.Data.Entity;
    using ContosoUniversity.Models;
    using System.Data.Entity.ModelConfiguration.Conventions;
    
    namespace ContosoUniversity.Models
    {
        public class SchoolContext : DbContext
        {
            public DbSet<Student> Students { get; set; }
            public DbSet<Enrollment> Enrollments { get; set; }
            public DbSet<Course> Courses { get; set; }
    
            protected override void OnModelCreating(DbModelBuilder modelBuilder)
            {
                modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
            }
        }
    }
    

    This sets up the database context, which is basically Entity Framework’s “setup”, from where it knows which C# class it has to map to database tables.

    So db.Students (from your question) is actually a DbSet<Student>.

    Entity Framework’s default convention looks like this: it tries to map a class to a table with the same name.
    Usually, it would map the Student class to a table named Students (pluralized), but you can change/override these conventions…which they also did in this example, in this line:

    modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
    

    This is also explained in the tutorial, directly under the above code.
    Quote from the tutorial:

    This code creates a DbSet property for each entity set. In Entity
    Framework terminology, an entity set typically corresponds to a
    database table, and an entity corresponds to a row in the table.

    The statement in the OnModelCreating method prevents table names from
    being pluralized. If you didn’t do this, the generated tables would be
    named Students, Courses, and Enrollments. Instead, the table names
    will be Student, Course, and Enrollment. Developers disagree about
    whether table names should be pluralized or not. This tutorial uses
    the singular form, but the important point is that you can select
    whichever form you prefer by including or omitting this line of code.

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

Sidebar

Related Questions

Whenever I create a new Empty MVC3 Web Application project in Visual Studio 2010
I'm trying to set up a new MVC 3 project. I have Visual Studio
I am using MS Visual Studio 2010. When i create a new MVC3 project
I am currently trying to set up a new visual studio 2008 solution while
I'm new to visual studio, coming from Delphi. I have a directory tree full
I am developing an MVC3 application using Visual Studio 2010. I have an aspx
I have created a new Visual Studio Setup Project that uses the output of
I am new to asp.net mvc3 and trying to get a connection going to
I am working on a web app in Visual Studio 2010, its mvc3. I
Visual Studio 2010 - C# - MVC3 I am completely new to ASP.Net and

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.