locked
creating a contact form need your help RRS feed

  • Question

  • User-507786106 posted

    I am creating a contact form and do not know how to create a drop down list with "States"

    I have:

    ContactController

    Model.States

    View (index)

    the error message is : {"Invalid object name 'dbo.States'."} Can you show me where things are falling apart....

    The table name is State and

     public class  tdb_Context : DbContext
        {
            private bool _isInitialized = false;

            public tdb_Context() : base("name=DB_ConnString")
            {
                 Database.SetInitializer<tdb_Context>(null);
            }

            public DbSet<Contact> Contact { get; set; }
            public DbSet<Services> Service { get; set; }
            public DbSet<States> State { get; set; }
            public DbSet<ErrorLogs> ErrorLogs { get; set; }       

        }

    Models

    Contacts

    Services

    States

    ErrorLogs

    DB Table names are

    Contact

    Service

    State

    ErrorLog

    Saturday, October 17, 2015 12:38 PM

Answers

  • User-821857111 posted

    By default, EF expects table names to be plurals of the DbSet name. You need to turn that convention off:

    ublic class  tdb_Context : DbContext
    {
        private bool _isInitialized = false;
    
        public tdb_Context() : base("name=DB_ConnString")
        {
             Database.SetInitializer<tdb_Context>(null);
        }
    
        public DbSet<Contact> Contact { get; set; }
        public DbSet<Services> Service { get; set; }
        public DbSet<States> State { get; set; }
        public DbSet<ErrorLogs> ErrorLogs { get; set; }        
    
    
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
        }    
    }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, October 19, 2015 3:06 AM