How to specify database name in Code First?

后端 未结 7 1328
广开言路
广开言路 2020-12-13 06:00

How do I tell EF what to name the database and where to put it?

If there is no connection string in the Web.Config, it tries to put it in the local SQLEXPRESS Server

7条回答
  •  自闭症患者
    2020-12-13 06:22

    in Class :

    public class Context : DbContext
    {
        //SET CONNECTION STRING NAME FOR DataBase Name :
        public Context() : base("YourConnectionName") { }
    
        public DbSet Categories { get; set; }
        public DbSet Products { get; set; }
    }
    

    in web.config:

      
        
      
    

    Thanks ferventcoder.
    Ref => http://brandonclapp.com/connection-strings-with-entity-framework-5-code-first/

提交回复
热议问题