Entity Framework: DbContext and setting the ProviderName

前端 未结 3 1571
难免孤独
难免孤独 2020-12-10 10:53

When you derive from DbContext and use the parameter-less constructor it will load a connection string from web.config. You also have the option of explicitly specifying the

3条回答
  •  Happy的楠姐
    2020-12-10 11:17

    Try like this ,

    public DBDataContext _dataContex;
    
    public DBDataContext DBContext 
        {
            get
            {
                if (_dataContex== null)
                {
                    _v= new DBDataContext(ConfigurationManager.ConnectionStrings["yourConnectinString"].ConnectionString);
                }
                return _dataContex;
            }
    
        }
    

提交回复
热议问题