LINQ to SQL connectionstring

前端 未结 6 2210
南旧
南旧 2020-12-09 22:29

I have an application that I want to be able to configure the connection string for my LINQ to SQL. I\'ve tried so many different ways but cannot seem to get it working. I w

6条回答
  •  余生分开走
    2020-12-09 23:04

    Inside your dbml file designer.cs add this dynamic call to base class constructor. It will work for local, dev and prod automatically pulling from current web.config without need to pass connection every time;

        public HallLockerDataContext() : 
        base(ConfigurationManager.ConnectionStrings["MYDB1"].ConnectionString, mappingSource)
        {
            OnCreated();
        }
    

    Usage:

        using (var db = new HallLockerDataContext())
        {
    
        }
    

提交回复
热议问题