Add a DbProviderFactory without an App.Config

前端 未结 8 1786
无人共我
无人共我 2020-12-13 06:52

I am using DbProviderFactories in my data layer (based on Entity Framework) and am using SQLite for my database, but I don\'t have to have a App.Config to have the following

8条回答
  •  北荒
    北荒 (楼主)
    2020-12-13 07:34

    see the following snippet

        public DataProviderManager(string ProviderName)
        {
    
           var  _Provider = DbProviderFactories.GetFactory(ProviderName);
    
        }
    

    you need to pass the ProviderName that in your case is "System.Data.SQLite".

    you don't need to create the app config section. That section is created by SQLite in the machine.config after the SQLite.net provider is installed.

    the whole purpose of the appconfig section is to help you get the list of configured .net providers when you call the following command:

    public GetProvidersList() { DataTable table= DbProviderFactories.GetFactoryClasses(); }

提交回复
热议问题