How to use more than one SQLite databases using LinqToDB

自作多情 提交于 2019-12-11 21:48:22

问题


I am using LinqToDB and LinqToDB.SQLite to access databases in my app. I have two separate and unique databases in my WPF app. I have two connection strings as such:

<add name="AddonManager" connectionString="Data Source=AddonManager.sqlite3" providerName="SQLite" />
<add name="AddonDb" connectionString="Data Source=AddonDb.sqlite3" providerName="SQLite" />

In code I try to access the second database (AddonDb) with the following code:

using (var dbContext = new DataModels.AddonDbDB())
{
    Guid newId = Guid.NewGuid();

    DataModels.Addon newAddon = new DataModels.Addon();
    newAddon.AddonGuid = newId.ToString();
    newAddon.AddonName = addonName;
    newAddon.GitUrl = gitUrl;

    dbContext.Insert(newAddon);

    return newId;
}

It seems to only reference the first connection string. If I move the second connection string up, it works. However that means the other database isn't accessible with the same problem.

I've tried to put a connection trying in the first line AddonDbDB("AddonDb.sqlite3") but I'm met with the error that it's not happy with the "configuration". I can't find anything in the documentation that even says having more than one database is even an option or even customization connection strings.

Has anyone ran across this before? I've dug through the, admittedly, very small set of SQLite examples and tried different combinations of connection strings. I've search through what "configuration" may be acceptable only to be met with very little information.

Why not put them in one database? Because one is downloaded from "the cloud" (lists) and the other is always stored locally (settings and personalized stuff). Thus the requirement of two databases.


回答1:


"configuration" - it is the name of your connection string in your config file. In your case, you have 2 configurations: "AddonManager" and "AddonDb"

In code you can do this

using ( var dbContex = new DataModels.AddonDbDB("AddonManager") )
{
    // your queries
}


来源:https://stackoverflow.com/questions/50259455/how-to-use-more-than-one-sqlite-databases-using-linqtodb

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!