A table in the corresponding database
[Table (Name = "Main. Student ")]
public class Student
{
[Column (Name = "Stuname", DbType = "varchar (50)")]
public string Stuname {get; set;}
[Column (Name = "Stuno", DbType = "varchar ()", IsPrimaryKey = True)]
public string Stuno {get; set;}
}
public class Sqlitedatacontext:datacontext
{
Public table<student> Students
{
Get
{
return gettable<student> ();
}
}
Public Sqlitedatacontext (idbconnection connection):
Base (Connection)
{
}
}
Working with SQLite Databases #region LINQ
Sqlitedatacontext context = new Sqlitedatacontext (SQLite. Connecttion);
/*
* Query and insert data
*/
var stu = context. Students.singleordefault (item = Item). Stuname.equals ("Fei Fei"));
if (Stu = = null)
{
Context. Students.insertonsubmit (New Student () {Stuno = "110525", Stuname = "Fly"});
Context. SubmitChanges ();
}
/*
* Query and delete data
*/
Stu = context. Students.single (item = Item). Stuname.equals ("Fei Fei"));
if (stu! = null)
{
Context. Students.deleteonsubmit (Stu);
Context. SubmitChanges ();
}
/*
* Query and modify data
*/
Stu = context. Students.single (item = Item). Stuname.equals ("Fei Fei"));
if (stu! = null)
{
Stu. Stuname = "Wu Gaofei";
Context. SubmitChanges ();
}
Console.readkey ();
#endregion