In C# using Nuget package using SQLite database and Linq to SQLite

Recommended for you: Get network issues from WhatsUp Gold. Not end users.

It is learning in VB using the SQLite database and Linq to SQLite, the first learn to use in C# SQLite database and Linq to SQLite, written with everyone to learn. (don't know is not work)

1,Create or open a C# project, if the new project you need to save it, otherwise unable to install the Nuget package.

2,Install the Nuget Linq to SQLite, open the Nuget package manager console:

 3,In the PM> installation command prompt input: (computer you want to network)

Install-Package linq2db.SQLite

4,After the success of the installation:

Dependencies are automatically added: System.Data.SQLite, linq2db, ling2db.t4models (Linq to SQLite to create a T4 template)

In the solution explorer add several:

 5,Now you can use the SQLite database.:

using System.Data.SQLite;

 Because of the C# code is not very familiar with, not to write specific connection method.

6,Implementation of Linq to SQLite:

Open the CopyMe.SQLite.tt.txt files in the LinqTODB.Template folder in Solution Explorer:

As shown below:

7,The first step template description, second are not, we directly to third, add the database connection in the Web/app.config file:

The properties window, open the solution selection ” “, add a ” connectionStrings“ connection string, save and set value:

Open the Web/app.config file, modify the file, add the providerName in the connectionString= "Data Source=E:\Address.db3"="SQLite":

The configuration file is as follows: (where E:\Address.db3 is the SQLite database file you)

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <configSections>
    </configSections>
    <connectionStrings>
        <add name="WindowsFormsApplication1.Properties.Settings.connectionStrings"
            connectionString="Data Source=E:\Address.db3" providerName="SQLite" />
    </connectionStrings>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
    </startup>
</configuration>

8,Back to the CopyMe.SQLite.tt.txt document window, save two position:

The first position is a database file directory, in this case should be revised as “ E:\”, the second position is the SQLite database file name, in this case should be “ Address.db3". (can also modify the NamespaceName to modify for your own namespace)

 9,In the Solution Explorer window, right-click the CopyMe.SQLite.tt.txt file renaming: "Address.tt", the file name casually, behind the.Txt removed, get the template file:

Asked whether the implementation template files window appears:

Determined in the Solution Explorer window a Linq to class SQLite:

10,You can now run the Linq To SQLite in your code.:

private void Form1_Load(object sender, EventArgs e)
        {
            var db=new DataModel.addressDB;
            var temp=
                from c in db.AddressDistricts 
                select c;
            foreach (var c in temp)
                    Console.WriteLine(c.DistrictName );

        }





Tragedy ah, VB when can achieve.

Title: Nuget Linq TO after SQLite package is very powerful, not only to achieve the Linq support for SQLite database, and realized Linq to Access, DB2, Firebird, Oracle and other 11 kinds of database support.










Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download

Posted by Hamiltion at November 15, 2013 - 1:59 AM