1
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SQLite;
using System.Data.Linq.Mapping;
using DbLinq.Data.Linq;
namespace LinqToSQLite
{
class Program
{
static void Main(string[] args)
{
string connectionString = "DbLinqProvider=Sqlite;Data Source=db2.sqlite";
DataContext db = new DataContext(connectionString);
db.ExecuteCommand(Person.CreateCommand);
Table<Person> table = db.GetTable<Person>();
table.InsertOnSubmit(new Person { Name = "Alfred" });
table.InsertOnSubmit(new Person { Name = "Brian" });
table.InsertOnSubmit(new Person { Name = "Charles" });
db.SubmitChanges();
var query = from p in table select p;
foreach (var p in query)
{
Console.WriteLine(p.ID + ". " + p.Name);
}
Console.WriteLine("Done");
Console.ReadLine();
}
}
[Table(Name = "Persons")]
class Person
{
[Column(IsPrimaryKey = true, IsDbGenerated = true)]
public int ID { get; set; }
[Column]
public string Name { get; set; }
public static string CreateCommand = "CREATE TABLE IF NOT EXISTS Persons (Id INTEGER PRIMARY KEY, Name TEXT)";
}
}
我創建了簡單的使用到的DBLinq提供LINQ到SQLite的應用程序,但它掛在db.SubmitChanges()
。什麼原因?我只是想在不使用DbMetal.exe的情況下創建簡單的dblinq應用程序......沒有錯誤,沒有例外,我很無能。簡單的LINQ to SQLite的應用程序掛起的SubmitChanges()