Add a DbProviderFactory without an App.Config

前端 未结 8 1785
无人共我
无人共我 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:21

    The following will probably cause sunspots and overthrow western civilization. It may even cause a debate about Duct Tape Programming (make it stop!), but it works (for now)

    try
    {
        var dataSet = ConfigurationManager.GetSection("system.data") as System.Data.DataSet;
        dataSet.Tables[0].Rows.Add("SQLite Data Provider"
        , ".Net Framework Data Provider for SQLite"
        , "System.Data.SQLite"
        , "System.Data.SQLite.SQLiteFactory, System.Data.SQLite");
    }
    catch (System.Data.ConstraintException) { }
    

提交回复
热议问题